From c60068667774548a30fab39689b01f04954b1f61 Mon Sep 17 00:00:00 2001 From: Chase Moran Date: Tue, 9 Nov 2021 11:17:25 -0500 Subject: [PATCH] bridge_ui: add polygon TVL stats Change-Id: I63cb04feadfc7da33a9acd52ac3b1af4a292f4ef --- .../src/components/Stats/CustodyAddresses.tsx | 7 +++ bridge_ui/src/components/Stats/NFTStats.tsx | 5 +- bridge_ui/src/hooks/useNFTTVL.ts | 52 ++++++++++++++++- bridge_ui/src/hooks/useTVL.ts | 56 ++++++++++++++++++- bridge_ui/src/utils/consts.ts | 2 + 5 files changed, 117 insertions(+), 5 deletions(-) diff --git a/bridge_ui/src/components/Stats/CustodyAddresses.tsx b/bridge_ui/src/components/Stats/CustodyAddresses.tsx index da4935e19..3235515d5 100644 --- a/bridge_ui/src/components/Stats/CustodyAddresses.tsx +++ b/bridge_ui/src/components/Stats/CustodyAddresses.tsx @@ -1,6 +1,7 @@ import { CHAIN_ID_BSC, CHAIN_ID_ETH, + CHAIN_ID_POLYGON, CHAIN_ID_SOLANA, CHAIN_ID_TERRA, } from "@certusone/wormhole-sdk"; @@ -60,6 +61,12 @@ const CustodyAddresses: React.FC = () => { tokenAddress: getTokenBridgeAddressForChain(CHAIN_ID_TERRA), nftAddress: null, }, + { + chainName: "Polygon", + chainId: CHAIN_ID_POLYGON, + tokenAddress: getTokenBridgeAddressForChain(CHAIN_ID_POLYGON), + nftAddress: getNFTBridgeAddressForChain(CHAIN_ID_POLYGON), + }, ]; }, []); diff --git a/bridge_ui/src/components/Stats/NFTStats.tsx b/bridge_ui/src/components/Stats/NFTStats.tsx index 7eff2e210..e63ed6fba 100644 --- a/bridge_ui/src/components/Stats/NFTStats.tsx +++ b/bridge_ui/src/components/Stats/NFTStats.tsx @@ -86,7 +86,10 @@ const useStyles = makeStyles((theme) => ({ }, })); -const BLACKLIST = ["D9cX654dGb4GFzqq3RY7rhZbRkQqUkfggDZdnYxqv97g"]; +const BLACKLIST = [ + "D9cX654dGb4GFzqq3RY7rhZbRkQqUkfggDZdnYxqv97g", + "0xfeA43A080297B02F2eBB88a27Cb0FA6DB1b33B1d", +]; const NFTStats: React.FC = () => { const classes = useStyles(); diff --git a/bridge_ui/src/hooks/useNFTTVL.ts b/bridge_ui/src/hooks/useNFTTVL.ts index 4bc58cc4a..4082325a3 100644 --- a/bridge_ui/src/hooks/useNFTTVL.ts +++ b/bridge_ui/src/hooks/useNFTTVL.ts @@ -2,6 +2,7 @@ import { ChainId, CHAIN_ID_BSC, CHAIN_ID_ETH, + CHAIN_ID_POLYGON, CHAIN_ID_SOLANA, } from "@certusone/wormhole-sdk"; import { TOKEN_PROGRAM_ID } from "@solana/spl-token"; @@ -20,6 +21,7 @@ import { COVALENT_GET_TOKENS_URL, ETH_NFT_BRIDGE_ADDRESS, getNFTBridgeAddressForChain, + POLYGON_NFT_BRIDGE_ADDRESS, SOLANA_HOST, SOL_NFT_CUSTODY_ADDRESS, } from "../utils/consts"; @@ -122,6 +124,11 @@ const useNFTTVL = (): DataWrapper => { const [bscCovalentIsLoading, setBscCovalentIsLoading] = useState(false); const [bscCovalentError, setBscCovalentError] = useState(""); + const [polygonCovalentData, setPolygonCovalentData] = useState(undefined); + const [polygonCovalentIsLoading, setPolygonCovalentIsLoading] = + useState(false); + const [polygonCovalentError, setPolygonCovalentError] = useState(""); + const [solanaCustodyTokens, setSolanaCustodyTokens] = useState< { pubkey: PublicKey; account: AccountInfo }[] | undefined >(undefined); @@ -154,6 +161,11 @@ const useNFTTVL = (): DataWrapper => { [bscCovalentData] ); + const polygonTVL = useMemo( + () => calcEvmTVL(polygonCovalentData, CHAIN_ID_POLYGON), + [polygonCovalentData] + ); + useEffect(() => { let cancelled = false; setEthCovalentIsLoading(true); @@ -210,6 +222,34 @@ const useNFTTVL = (): DataWrapper => { ); }, []); + useEffect(() => { + let cancelled = false; + setPolygonCovalentIsLoading(true); + axios + .get( + COVALENT_GET_TOKENS_URL( + CHAIN_ID_POLYGON, + POLYGON_NFT_BRIDGE_ADDRESS, + true, + false + ) + ) + .then( + (results) => { + if (!cancelled) { + setPolygonCovalentData(results.data); + setPolygonCovalentIsLoading(false); + } + }, + (error) => { + if (!cancelled) { + setPolygonCovalentError("Unable to retrieve Polygon TVL."); + setPolygonCovalentIsLoading(false); + } + } + ); + }, []); + useEffect(() => { let cancelled = false; const connection = new Connection(SOLANA_HOST, "confirmed"); @@ -237,14 +277,19 @@ const useNFTTVL = (): DataWrapper => { }, []); return useMemo(() => { - const tvlArray = [...ethTVL, ...bscTVL, ...solanaTVL]; + const tvlArray = [...ethTVL, ...bscTVL, ...polygonTVL, ...solanaTVL]; return { isFetching: ethCovalentIsLoading || bscCovalentIsLoading || + polygonCovalentIsLoading || solanaCustodyTokensLoading, - error: ethCovalentError || bscCovalentError || solanaCustodyTokensError, + error: + ethCovalentError || + bscCovalentError || + polygonCovalentError || + solanaCustodyTokensError, receivedAt: null, data: tvlArray, }; @@ -253,6 +298,9 @@ const useNFTTVL = (): DataWrapper => { ethCovalentIsLoading, bscCovalentError, bscCovalentIsLoading, + polygonTVL, + polygonCovalentError, + polygonCovalentIsLoading, ethTVL, bscTVL, solanaTVL, diff --git a/bridge_ui/src/hooks/useTVL.ts b/bridge_ui/src/hooks/useTVL.ts index 23207ba54..13132f01a 100644 --- a/bridge_ui/src/hooks/useTVL.ts +++ b/bridge_ui/src/hooks/useTVL.ts @@ -2,6 +2,7 @@ import { ChainId, CHAIN_ID_BSC, CHAIN_ID_ETH, + CHAIN_ID_POLYGON, CHAIN_ID_SOLANA, CHAIN_ID_TERRA, } from "@certusone/wormhole-sdk"; @@ -22,6 +23,7 @@ import { CHAINS_BY_ID, COVALENT_GET_TOKENS_URL, ETH_TOKEN_BRIDGE_ADDRESS, + POLYGON_TOKEN_BRIDGE_ADDRESS, SOLANA_HOST, SOL_CUSTODY_ADDRESS, TERRA_SWAPRATE_URL, @@ -276,6 +278,11 @@ const useTVL = (): DataWrapper => { const [bscCovalentIsLoading, setBscCovalentIsLoading] = useState(false); const [bscCovalentError, setBscCovalentError] = useState(""); + const [polygonCovalentData, setPolygonCovalentData] = useState(undefined); + const [polygonCovalentIsLoading, setPolygonCovalentIsLoading] = + useState(false); + const [polygonCovalentError, setPolygonCovalentError] = useState(""); + const [solanaCustodyTokens, setSolanaCustodyTokens] = useState< { pubkey: PublicKey; account: AccountInfo }[] | undefined >(undefined); @@ -311,6 +318,10 @@ const useTVL = (): DataWrapper => { () => calcEvmTVL(bscCovalentData, CHAIN_ID_BSC), [bscCovalentData] ); + const polygonTVL = useMemo( + () => calcEvmTVL(polygonCovalentData, CHAIN_ID_POLYGON), + [polygonCovalentData] + ); useEffect(() => { let cancelled = false; @@ -358,6 +369,33 @@ const useTVL = (): DataWrapper => { ); }, []); + useEffect(() => { + let cancelled = false; + setPolygonCovalentIsLoading(true); + axios + .get( + COVALENT_GET_TOKENS_URL( + CHAIN_ID_POLYGON, + POLYGON_TOKEN_BRIDGE_ADDRESS, + false + ) + ) + .then( + (results) => { + if (!cancelled) { + setPolygonCovalentData(results.data); + setPolygonCovalentIsLoading(false); + } + }, + (error) => { + if (!cancelled) { + setPolygonCovalentError("Unable to retrieve Polygon TVL."); + setPolygonCovalentIsLoading(false); + } + } + ); + }, []); + useEffect(() => { let cancelled = false; const connection = new Connection(SOLANA_HOST, "confirmed"); @@ -385,15 +423,26 @@ const useTVL = (): DataWrapper => { }, []); return useMemo(() => { - const tvlArray = [...ethTVL, ...bscTVL, ...solanaTVL, ...terraTVL]; + const tvlArray = [ + ...ethTVL, + ...bscTVL, + ...polygonTVL, + ...solanaTVL, + ...terraTVL, + ]; return { isFetching: ethCovalentIsLoading || bscCovalentIsLoading || + polygonCovalentIsLoading || solanaCustodyTokensLoading || isTerraLoading, - error: ethCovalentError || bscCovalentError || solanaCustodyTokensError, + error: + ethCovalentError || + bscCovalentError || + polygonCovalentError || + solanaCustodyTokensError, receivedAt: null, data: tvlArray, }; @@ -402,6 +451,9 @@ const useTVL = (): DataWrapper => { ethCovalentIsLoading, bscCovalentError, bscCovalentIsLoading, + polygonCovalentError, + polygonCovalentIsLoading, + polygonTVL, ethTVL, bscTVL, solanaTVL, diff --git a/bridge_ui/src/utils/consts.ts b/bridge_ui/src/utils/consts.ts index 2d993af4c..7e3412fe0 100644 --- a/bridge_ui/src/utils/consts.ts +++ b/bridge_ui/src/utils/consts.ts @@ -625,6 +625,8 @@ export const VAA_EMITTER_ADDRESSES = [ `${CHAIN_ID_TERRA}:0000000000000000000000007cf7b764e38a0a5e967972c1df77d432510564e2`, //terra `${CHAIN_ID_BSC}:000000000000000000000000b6f6d86a8f9879a9c87f643768d9efc38c1da6e7`, //bsc `${CHAIN_ID_BSC}:0000000000000000000000005a58505a96d1dbf8df91cb21b54419fc36e93fde`, //bsc nft + `${CHAIN_ID_POLYGON}:0000000000000000000000005a58505a96d1dbf8df91cb21b54419fc36e93fde`, //Polygon + `${CHAIN_ID_POLYGON}:00000000000000000000000090bbd86a6fe93d3bc3ed6335935447e75fab7fcf`, //Polygon nft ]; export const WORMHOLE_EXPLORER_BASE = "https://wormholenetwork.com/en/explorer";