Skip to content

Commit

Permalink
bridge_ui: add polygon TVL stats
Browse files Browse the repository at this point in the history
Change-Id: I63cb04feadfc7da33a9acd52ac3b1af4a292f4ef
  • Loading branch information
chase-45 committed Nov 9, 2021
1 parent be244f4 commit c600686
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 5 deletions.
7 changes: 7 additions & 0 deletions bridge_ui/src/components/Stats/CustodyAddresses.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CHAIN_ID_BSC,
CHAIN_ID_ETH,
CHAIN_ID_POLYGON,
CHAIN_ID_SOLANA,
CHAIN_ID_TERRA,
} from "@certusone/wormhole-sdk";
Expand Down Expand Up @@ -60,6 +61,12 @@ const CustodyAddresses: React.FC<any> = () => {
tokenAddress: getTokenBridgeAddressForChain(CHAIN_ID_TERRA),
nftAddress: null,
},
{
chainName: "Polygon",
chainId: CHAIN_ID_POLYGON,
tokenAddress: getTokenBridgeAddressForChain(CHAIN_ID_POLYGON),
nftAddress: getNFTBridgeAddressForChain(CHAIN_ID_POLYGON),
},
];
}, []);

Expand Down
5 changes: 4 additions & 1 deletion bridge_ui/src/components/Stats/NFTStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ const useStyles = makeStyles((theme) => ({
},
}));

const BLACKLIST = ["D9cX654dGb4GFzqq3RY7rhZbRkQqUkfggDZdnYxqv97g"];
const BLACKLIST = [
"D9cX654dGb4GFzqq3RY7rhZbRkQqUkfggDZdnYxqv97g",
"0xfeA43A080297B02F2eBB88a27Cb0FA6DB1b33B1d",
];

const NFTStats: React.FC<any> = () => {
const classes = useStyles();
Expand Down
52 changes: 50 additions & 2 deletions bridge_ui/src/hooks/useNFTTVL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -122,6 +124,11 @@ const useNFTTVL = (): DataWrapper<NFTTVL[]> => {
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<ParsedAccountData> }[] | undefined
>(undefined);
Expand Down Expand Up @@ -154,6 +161,11 @@ const useNFTTVL = (): DataWrapper<NFTTVL[]> => {
[bscCovalentData]
);

const polygonTVL = useMemo(
() => calcEvmTVL(polygonCovalentData, CHAIN_ID_POLYGON),
[polygonCovalentData]
);

useEffect(() => {
let cancelled = false;
setEthCovalentIsLoading(true);
Expand Down Expand Up @@ -210,6 +222,34 @@ const useNFTTVL = (): DataWrapper<NFTTVL[]> => {
);
}, []);

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");
Expand Down Expand Up @@ -237,14 +277,19 @@ const useNFTTVL = (): DataWrapper<NFTTVL[]> => {
}, []);

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,
};
Expand All @@ -253,6 +298,9 @@ const useNFTTVL = (): DataWrapper<NFTTVL[]> => {
ethCovalentIsLoading,
bscCovalentError,
bscCovalentIsLoading,
polygonTVL,
polygonCovalentError,
polygonCovalentIsLoading,
ethTVL,
bscTVL,
solanaTVL,
Expand Down
56 changes: 54 additions & 2 deletions bridge_ui/src/hooks/useTVL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -276,6 +278,11 @@ const useTVL = (): DataWrapper<TVL[]> => {
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<ParsedAccountData> }[] | undefined
>(undefined);
Expand Down Expand Up @@ -311,6 +318,10 @@ const useTVL = (): DataWrapper<TVL[]> => {
() => calcEvmTVL(bscCovalentData, CHAIN_ID_BSC),
[bscCovalentData]
);
const polygonTVL = useMemo(
() => calcEvmTVL(polygonCovalentData, CHAIN_ID_POLYGON),
[polygonCovalentData]
);

useEffect(() => {
let cancelled = false;
Expand Down Expand Up @@ -358,6 +369,33 @@ const useTVL = (): DataWrapper<TVL[]> => {
);
}, []);

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");
Expand Down Expand Up @@ -385,15 +423,26 @@ const useTVL = (): DataWrapper<TVL[]> => {
}, []);

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,
};
Expand All @@ -402,6 +451,9 @@ const useTVL = (): DataWrapper<TVL[]> => {
ethCovalentIsLoading,
bscCovalentError,
bscCovalentIsLoading,
polygonCovalentError,
polygonCovalentIsLoading,
polygonTVL,
ethTVL,
bscTVL,
solanaTVL,
Expand Down
2 changes: 2 additions & 0 deletions bridge_ui/src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit c600686

Please sign in to comment.