From 9e10841a349c35345219eceeb45395ddfab35ee5 Mon Sep 17 00:00:00 2001 From: Matthew Pereira Date: Wed, 13 Mar 2024 16:16:04 -0700 Subject: [PATCH] read some deployed contract info --- packages/nextjs/app/pools/page.tsx | 18 +++++-- .../components/balancer/PoolDetails.tsx | 42 ++++++++++++++++ packages/nextjs/components/balancer/index.tsx | 1 + packages/nextjs/hooks/balancer/index.ts | 1 + .../nextjs/hooks/balancer/usePoolContract.ts | 50 +++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 packages/nextjs/components/balancer/PoolDetails.tsx create mode 100644 packages/nextjs/components/balancer/index.tsx create mode 100644 packages/nextjs/hooks/balancer/index.ts create mode 100644 packages/nextjs/hooks/balancer/usePoolContract.ts diff --git a/packages/nextjs/app/pools/page.tsx b/packages/nextjs/app/pools/page.tsx index e8442ff3..249ec5e2 100644 --- a/packages/nextjs/app/pools/page.tsx +++ b/packages/nextjs/app/pools/page.tsx @@ -1,17 +1,25 @@ +"use client"; + import type { NextPage } from "next"; +import { PoolDetails } from "~~/components/balancer/PoolDetails"; const Pools: NextPage = () => { return ( <>
-
+

🌊 Pools

-

- Lorem ipsum dolor sit, amet consectetur adipisicing elit. Eveniet nemo praesentium molestias impedit - mollitia quisquam fugit nobis possimus quis enim omnis similique repudiandae odit nihil deleniti harum - tempora, quod exercitationem? +

+ Balancer is infinitely extensible to allow for any conceivable pool type with custom curves, logic, + parameters, and more. Each pool deployed to balancer is its own smart contract. This tool allows you to + interact with any pool currently deployed (custom or existing). To get started, enter the contract address + of the desired pool below.

+ +
+ +
); diff --git a/packages/nextjs/components/balancer/PoolDetails.tsx b/packages/nextjs/components/balancer/PoolDetails.tsx new file mode 100644 index 00000000..d087ce93 --- /dev/null +++ b/packages/nextjs/components/balancer/PoolDetails.tsx @@ -0,0 +1,42 @@ +import { formatUnits } from "viem"; +import { Address } from "~~/components/scaffold-eth"; +import { usePoolContract } from "~~/hooks/balancer"; + +/** + * Display all the contract details for a balancer pool + */ +export const PoolDetails = () => { + const pool = usePoolContract("ConstantPricePool"); + return ( +
+
+
Name:
+
{pool.name}
+
+ +
+
Symbol:
+
({pool.symbol})
+
+ +
+
Pool Address:
+
+
+
+
+ +
+
Vault Address:
+
+
+
+
+ +
+
Total Supply:
+
{formatUnits(pool.totalSupply || 0n, pool.decimals || 18)}
+
+
+ ); +}; diff --git a/packages/nextjs/components/balancer/index.tsx b/packages/nextjs/components/balancer/index.tsx new file mode 100644 index 00000000..77a44f65 --- /dev/null +++ b/packages/nextjs/components/balancer/index.tsx @@ -0,0 +1 @@ +export * from "./PoolDetails"; diff --git a/packages/nextjs/hooks/balancer/index.ts b/packages/nextjs/hooks/balancer/index.ts new file mode 100644 index 00000000..ea55fb05 --- /dev/null +++ b/packages/nextjs/hooks/balancer/index.ts @@ -0,0 +1 @@ +export * from "./usePoolContract"; diff --git a/packages/nextjs/hooks/balancer/usePoolContract.ts b/packages/nextjs/hooks/balancer/usePoolContract.ts new file mode 100644 index 00000000..0e60ef66 --- /dev/null +++ b/packages/nextjs/hooks/balancer/usePoolContract.ts @@ -0,0 +1,50 @@ +import { useDeployedContractInfo, useScaffoldContractRead } from "~~/hooks/scaffold-eth"; + +export interface PoolDetails { + name: string | undefined; + address: string | undefined; + symbol: string | undefined; + decimals: number | undefined; + totalSupply: bigint | undefined; + vaultAddress: string | undefined; +} + +type DeployedPoolNames = "ConstantPricePool"; + +export const usePoolContract = (contractName: DeployedPoolNames): PoolDetails => { + const { data: deployedContractData } = useDeployedContractInfo(contractName); + + const { data: name } = useScaffoldContractRead({ + contractName, + functionName: "name", + }); + + const { data: symbol } = useScaffoldContractRead({ + contractName, + functionName: "symbol", + }); + + const { data: totalSupply } = useScaffoldContractRead({ + contractName, + functionName: "totalSupply", + }); + + const { data: decimals } = useScaffoldContractRead({ + contractName, + functionName: "decimals", + }); + + const { data: vaultAddress } = useScaffoldContractRead({ + contractName, + functionName: "getVault", + }); + + return { + name, + address: deployedContractData?.address, + symbol, + totalSupply: totalSupply, + decimals, + vaultAddress, + }; +};