Skip to content

Commit

Permalink
dashboard: add testnet NTT accountant
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Mar 8, 2024
1 parent ae37cdb commit 6700cac
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 27 deletions.
36 changes: 24 additions & 12 deletions dashboard/src/components/Accountant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,25 +263,37 @@ const overviewColumns = [
}),
];

function Accountant({ governorInfo }: { governorInfo: CloudGovernorInfo }) {
const pendingTransferInfo = useGetAccountantPendingTransfers();
function Accountant({
governorInfo,
accountantAddress,
isNTT,
}: {
governorInfo?: CloudGovernorInfo;
accountantAddress: string;
isNTT?: boolean;
}) {
const pendingTransferInfo = useGetAccountantPendingTransfers(accountantAddress);

const accountsInfo = useGetAccountantAccounts();
const accountsInfo = useGetAccountantAccounts(accountantAddress);

const tokenData = useTokenData();
const tokenData = useTokenData(isNTT);

const governorInfoIsDefined = !!governorInfo;

const pendingTransfersForAcct: PendingTransferForAcct[] = useMemo(
() =>
pendingTransferInfo.map((transfer) => ({
...transfer,
isEnqueuedInGov: !!governorInfo.enqueuedVAAs.find(
(vaa) =>
vaa.emitterChain === transfer.key.emitter_chain &&
vaa.emitterAddress === transfer.key.emitter_address &&
vaa.sequence === transfer.key.sequence.toString()
),
isEnqueuedInGov:
governorInfoIsDefined &&
!!governorInfo.enqueuedVAAs.find(
(vaa) =>
vaa.emitterChain === transfer.key.emitter_chain &&
vaa.emitterAddress === transfer.key.emitter_address &&
vaa.sequence === transfer.key.sequence.toString()
),
})),
[pendingTransferInfo, governorInfo.enqueuedVAAs]
[pendingTransferInfo, governorInfoIsDefined, governorInfo?.enqueuedVAAs]
);

const guardianSigningStats: GuardianSigningStat[] = useMemo(() => {
Expand Down Expand Up @@ -424,7 +436,7 @@ function Accountant({ governorInfo }: { governorInfo: CloudGovernorInfo }) {
paddingRight: 1,
}}
>
<Box>Accountant</Box>
<Box>{isNTT ? 'NTT ' : ''}Accountant</Box>
<Box flexGrow={1} />
<Box sx={{ display: 'flex', alignItems: 'center', flexWrap: 'wrap' }}>
{Object.keys(pendingByChain)
Expand Down
12 changes: 11 additions & 1 deletion dashboard/src/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import Governor from './Governor';
import Guardians from './Guardians';
import MainnetGovernor from './MainnetGovernor';
import Monitor from './Monitor';
import {
ACCOUNTANT_CONTRACT_ADDRESS,
NTT_ACCOUNTANT_CONTRACT_ADDRESS_TESTNET,
} from '../utils/consts';

function Home({
heartbeats,
Expand All @@ -37,7 +41,7 @@ function Home({
<>
<MainnetGovernor governorInfo={governorInfo} />
<Divider />
<Accountant governorInfo={governorInfo} />
<Accountant governorInfo={governorInfo} accountantAddress={ACCOUNTANT_CONTRACT_ADDRESS} />
<Divider />
<MonitorSettingsProvider>
<CollapsibleSection header="Monitor">
Expand All @@ -47,6 +51,12 @@ function Home({
</>
) : currentNetwork.name === 'Testnet' ? (
<>
<Accountant
governorInfo={governorInfo}
accountantAddress={NTT_ACCOUNTANT_CONTRACT_ADDRESS_TESTNET}
isNTT
/>
<Divider />
<MonitorSettingsProvider>
<CollapsibleSection header="Monitor">
<Monitor />
Expand Down
14 changes: 8 additions & 6 deletions dashboard/src/hooks/useGetAccountantAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { useEffect, useState } from 'react';
import { useNetworkContext } from '../contexts/NetworkContext';
import { ACCOUNTANT_CONTRACT_ADDRESS, WORMCHAIN_URL } from '../utils/consts';
import { TESTNET_WORMCHAIN_URL, WORMCHAIN_URL } from '../utils/consts';

const POLL_INTERVAL_MS = 1 * 60 * 1000;
const PAGE_LIMIT = 2000; // throws a gas limit error over this
Expand All @@ -15,24 +15,26 @@ export type Account = {
balance: string;
};

const useGetAccountantAccounts = (): Account[] => {
const useGetAccountantAccounts = (contractAddress: string): Account[] => {
const { currentNetwork } = useNetworkContext();
const [accountantInfo, setAccountantInfo] = useState<Account[]>([]);

useEffect(() => {
if (currentNetwork.name !== 'Mainnet') {
if (currentNetwork.name !== 'Mainnet' && currentNetwork.name !== 'Testnet') {
return;
}
let cancelled = false;
(async () => {
while (!cancelled) {
try {
const cosmWasmClient = await CosmWasmClient.connect(WORMCHAIN_URL);
const cosmWasmClient = await CosmWasmClient.connect(
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL
);
let accounts: Account[] = [];
let response;
let start_after = undefined;
do {
response = await cosmWasmClient.queryContractSmart(ACCOUNTANT_CONTRACT_ADDRESS, {
response = await cosmWasmClient.queryContractSmart(contractAddress, {
all_accounts: {
limit: PAGE_LIMIT,
start_after,
Expand All @@ -59,7 +61,7 @@ const useGetAccountantAccounts = (): Account[] => {
return () => {
cancelled = true;
};
}, [currentNetwork]);
}, [currentNetwork, contractAddress]);

return accountantInfo;
};
Expand Down
14 changes: 8 additions & 6 deletions dashboard/src/hooks/useGetAccountantPendingTransfers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { useEffect, useState } from 'react';
import { useNetworkContext } from '../contexts/NetworkContext';
import { ACCOUNTANT_CONTRACT_ADDRESS, WORMCHAIN_URL } from '../utils/consts';
import { TESTNET_WORMCHAIN_URL, WORMCHAIN_URL } from '../utils/consts';

const POLL_INTERVAL_MS = 10 * 1000;
const PAGE_LIMIT = 2000; // throws a gas limit error over this
Expand All @@ -25,24 +25,26 @@ export type PendingTransfer = {
];
};

const useGetAccountantPendingTransfers = (): PendingTransfer[] => {
const useGetAccountantPendingTransfers = (contractAddress: string): PendingTransfer[] => {
const { currentNetwork } = useNetworkContext();
const [accountantInfo, setAccountantInfo] = useState<PendingTransfer[]>([]);

useEffect(() => {
if (currentNetwork.name !== 'Mainnet') {
if (currentNetwork.name !== 'Mainnet' && currentNetwork.name !== 'Testnet') {
return;
}
let cancelled = false;
(async () => {
while (!cancelled) {
try {
const cosmWasmClient = await CosmWasmClient.connect(WORMCHAIN_URL);
const cosmWasmClient = await CosmWasmClient.connect(
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL
);
let pending: PendingTransfer[] = [];
let response;
let start_after = undefined;
do {
response = await cosmWasmClient.queryContractSmart(ACCOUNTANT_CONTRACT_ADDRESS, {
response = await cosmWasmClient.queryContractSmart(contractAddress, {
all_pending_transfers: {
limit: PAGE_LIMIT,
start_after,
Expand All @@ -69,7 +71,7 @@ const useGetAccountantPendingTransfers = (): PendingTransfer[] => {
return () => {
cancelled = true;
};
}, [currentNetwork]);
}, [currentNetwork, contractAddress]);

return accountantInfo;
};
Expand Down
5 changes: 3 additions & 2 deletions dashboard/src/hooks/useTokenData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export type TokenDataByChainAddress = {
[chainAddress: string]: TokenDataEntry;
};

function useTokenData(): TokenDataByChainAddress | null {
function useTokenData(skip?: boolean): TokenDataByChainAddress | null {
const { currentNetwork } = useNetworkContext();
const [tokenData, setTokenData] = useState<TokenDataByChainAddress | null>(null);
useEffect(() => {
if (skip) return;
let cancelled = false;
(async () => {
while (!cancelled) {
Expand All @@ -41,7 +42,7 @@ function useTokenData(): TokenDataByChainAddress | null {
return () => {
cancelled = true;
};
}, [currentNetwork]);
}, [currentNetwork, skip]);
return tokenData;
}
export default useTokenData;
5 changes: 5 additions & 0 deletions dashboard/src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import xplaIcon from '../images/xpla.svg';
require('dotenv').config();

export const WORMCHAIN_URL = 'https://tncnt-eu-wormchain-main-01.rpc.p2p.world';
export const TESTNET_WORMCHAIN_URL = `https://corsproxy.io/?${encodeURIComponent(
'https://gateway.testnet.xlabs.xyz'
)}`;

export const CHAIN_ICON_MAP: { [key: string]: string } = {
1: solanaIcon,
Expand Down Expand Up @@ -92,6 +95,8 @@ export const CHAIN_ICON_MAP: { [key: string]: string } = {
export const JUMP_GUARDIAN_ADDRESS = '58cc3ae5c097b213ce3c81979e1b9f9570746aa5';
export const ACCOUNTANT_CONTRACT_ADDRESS =
'wormhole14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9srrg465';
export const NTT_ACCOUNTANT_CONTRACT_ADDRESS_TESTNET =
'wormhole169tvyx49zmjqhlv7mzwj8j2weprascc0jq3rdglw9pynldqx34nscvhc7k';

export const GUARDIAN_SET_3 = [
{
Expand Down

0 comments on commit 6700cac

Please sign in to comment.