Skip to content

Commit

Permalink
dashboard: solana ntt rate limit queries
Browse files Browse the repository at this point in the history
Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>
  • Loading branch information
bingyuyap authored and evan-gray committed Apr 16, 2024
1 parent 5c573ca commit 7ec332d
Show file tree
Hide file tree
Showing 14 changed files with 482 additions and 940 deletions.
1 change: 1 addition & 0 deletions common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './consts';
export * from './explorer';
export * from './solana';
export * from './utils';
export * from './nttConsts';
105 changes: 105 additions & 0 deletions common/src/nttConsts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Chain, Network, chains } from '@wormhole-foundation/sdk-base';

// This data structure is used in dashboard
export type NTTContract = {
[key in Network]: { [tokenName: string]: { [key in Chain]?: string } };
};

// This data structure is used in watchers
export type NTTContractArray = {
[key in Network]: { [key in Chain]?: string[] };
};

function convertNTTManagerContractToNTTContractArray(
nttManagerContract: NTTContract
): NTTContractArray {
const nttContract: NTTContractArray = {} as NTTContractArray;

for (const network in nttManagerContract) {
nttContract[network as Network] = {};

for (const tokenName in nttManagerContract[network as Network]) {
for (const chain in nttManagerContract[network as Network][tokenName]) {
const tokenAddress = nttManagerContract[network as Network][tokenName][chain as Chain];

if (tokenAddress) {
if (!nttContract[network as Network][chain as Chain]) {
nttContract[network as Network][chain as Chain] = [];
}
nttContract[network as Network][chain as Chain]!.push(tokenAddress);
}
}
}
}

return nttContract;
}

export const NTT_MANAGER_CONTRACT: NTTContract = {
Mainnet: {
USDC: {
Ethereum: '0xeBdCe9a913d9400EE75ef31Ce8bd34462D01a1c1',
Fantom: '0x68dB2f05Aa2d77DEf981fd2be32661340c9222FB',
},
},
Testnet: {
TEST_NTT: {
Solana: 'nTTh3bZ5Aer6xboWZe39RDEft4MeVxSQ8D1EYAVLZw9',
Sepolia: '0xB231aD95f2301bc82eA44c515001F0F746D637e0',
ArbitrumSepolia: '0xEec94CD3083e067398256a79CcA7e740C5c8ef81',
BaseSepolia: '0xB03b030b2f5B40819Df76467d67eD1C85Ff66fAD',
OptimismSepolia: '0x7f430D4e7939D994C0955A01FC75D9DE33F12D11',
},
},
Devnet: {},
};

export const NTT_TRANSCEIVER_CONTRACT: NTTContract = {
Mainnet: {
USDC: {
Ethereum: '0x55f7820357FA17A1ECb48E959D5E637bFF956d6F',
Fantom: '0x8b47f02E7E20174C76Af910adc0Ad8A4B0342f4c',
},
},
Testnet: {
TEST_NTT: {
Solana: '9WNzy7xYZyL2k6JnE9dWSp7VpYkvfRN3Rhd8wHv9J9mY',
Sepolia: '0x1fDC902e30b188FD2BA976B421Cb179943F57896',
ArbitrumSepolia: '0x0E24D17D7467467b39Bf64A9DFf88776Bd6c74d7',
BaseSepolia: '0x1e072169541f1171e427Aa44B5fd8924BEE71b0e',
OptimismSepolia: '0x41265eb2863bf0238081F6AeefeF73549C82C3DD',
},
},
Devnet: {},
};

export const NTT_TOKENS: NTTContract = {
Mainnet: {
USDC: {
Ethereum: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
Fantom: '0x2F733095B80A04b38b0D10cC884524a3d09b836a',
},
},
Testnet: {
TEST_NTT: {
Solana: '87r5ZS91Q2pQbFTvvneqs7y7mbtegtqMt4LDAS4g23Ax',
Sepolia: '0x1d30E78B7C7fbbcef87ae6e97B5389b2e470CA4a',
ArbitrumSepolia: '0x84A1Cb660B19eB0063EE5FD377eC14AAe3364d74',
BaseSepolia: '0x7f430D4e7939D994C0955A01FC75D9DE33F12D11',
OptimismSepolia: '0x0e15979a7a1eFAEf20312CA45A59eb141bF7E340',
},
},
Devnet: {},
};

export const NTT_MANAGER_CONTRACT_ARRAY =
convertNTTManagerContractToNTTContractArray(NTT_MANAGER_CONTRACT);

export function NTT_SUPPORTED_CHAINS(network: Network, token: string): Chain[] {
const contractDetails = NTT_MANAGER_CONTRACT[network][token];
if (!contractDetails) {
return [];
}

return chains.filter((chain) => chain in contractDetails);
}
1 change: 0 additions & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"axios": "^0.27.2",
"ethers": "^6.11.1",
"numeral": "^2.0.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/components/NTTMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function NTTMetrics() {
src="https://lookerstudio.google.com/embed/reporting/0f20bce5-d442-4f39-8cc4-ced8bb73042a/page/kSKuD"
hasTabs
/>
<NTTRateLimits />
</>
);
}
Expand Down
61 changes: 48 additions & 13 deletions dashboard/src/components/NTTRateLimits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,40 @@ import { chainIdToName } from '@wormhole-foundation/wormhole-monitor-common';
const rateLimitColumnHelper = createColumnHelper<RateLimit>();

const rateLimitColumns = [
rateLimitColumnHelper.accessor('tokenName', {
id: 'tokenName',
header: () => 'Token',
cell: (info) => (
<>
{info.row.getCanExpand() && !info.row.original.srcChain ? (
<IconButton
size="small"
sx={{ ml: -1 }}
{...{
onClick: info.row.getToggleExpandedHandler(),
}}
>
{info.row.getIsExpanded() ? (
<KeyboardArrowDown fontSize="inherit" />
) : (
<KeyboardArrowRight fontSize="inherit" />
)}
</IconButton>
) : null}{' '}
{info.row.original.srcChain
? info.row.original.destChain
? null
: null
: info.row.original.tokenName}
</>
),
}),
rateLimitColumnHelper.accessor((row) => row.srcChain, {
id: 'srcChain',
header: () => 'Chain',
cell: (info) => (
<>
{info.row.getCanExpand() ? (
{info.row.getCanExpand() && info.row.original.srcChain ? (
<IconButton
size="small"
sx={{ ml: -1 }}
Expand All @@ -38,32 +66,38 @@ const rateLimitColumns = [
<KeyboardArrowRight fontSize="inherit" />
)}
</IconButton>
) : null}{' '}
{info.row.original.destChain ? (
<Box sx={{ pl: 3 }}>
{chainIdToName(info.row.original.destChain)} ({info.row.original.destChain})
</Box>
) : (
`${chainIdToName(info.row.original.srcChain)} (${info.row.original.srcChain})`
)}
<Box sx={{ width: 20, display: 'inline-block' }} />
)}{' '}
{info.row.original.srcChain
? info.row.original.destChain
? `${chainIdToName(info.row.original.destChain)}(${info.row.original.destChain})`
: `${chainIdToName(info.row.original.srcChain)}(${info.row.original.srcChain})`
: null}
</>
),
}),
rateLimitColumnHelper.accessor('amount', {
header: () => <Box order="1">Outbound Capacity</Box>,
cell: (info) => (
<Box textAlign="right">
{info.row.original.destChain ? null : `$${info.row.original.amount.toLocaleString()}`}
{info.row.original.srcChain
? info.row.original.destChain
? null
: `${info.row.original.amount?.toLocaleString()}`
: null}
</Box>
),
}),
rateLimitColumnHelper.accessor('totalInboundCapacity', {
header: () => <Box order="1">Inbound Capacity</Box>,
cell: (info) => (
<Box textAlign="right">
{info.row.original.destChain
? `$${info.row.original.amount.toLocaleString()}`
: `$${info.row.original.totalInboundCapacity?.toLocaleString()}`}
{info.row.original.srcChain
? info.row.original.destChain
? info.row.original.amount?.toLocaleString()
: `${info.row.original.totalInboundCapacity?.toLocaleString()}`
: null}
</Box>
),
}),
Expand All @@ -83,7 +117,8 @@ export function NTTRateLimits() {
sorting: rateLimitSorting,
},
getSubRows: (row) => row.inboundCapacity,
getRowId: (rateLimit) => `${rateLimit.srcChain.toString()}-${rateLimit.destChain || ''}`,
getRowId: (rateLimit) =>
`${rateLimit.tokenName.toString()}-${rateLimit.srcChain || ''}-${rateLimit.destChain || ''}`,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
getExpandedRowModel: getExpandedRowModel(),
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/hooks/useRateLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState, useEffect } from 'react';
import { RateLimit, getRateLimits } from '../utils/nttHelpers';
import { Network } from '../contexts/NetworkContext';

const REFRESH_INTERVAL = 60_000; // 1 minute
const REFRESH_INTERVAL = 120_000; // 2 minutes

export function useRateLimits(network: Network) {
const [rateLimits, setRateLimits] = useState<RateLimit[]>([]);
Expand All @@ -14,6 +14,8 @@ export function useRateLimits(network: Network) {
const fetchRateLimits = async () => {
if (cancelled) return;
const limits = await getRateLimits(network);
limits.sort((a, b) => a.tokenName.localeCompare(b.tokenName));
if (cancelled) return;
setRateLimits(limits);
};

Expand Down
43 changes: 0 additions & 43 deletions dashboard/src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import terraIcon from '../images/terra.svg';
import terra2Icon from '../images/terra2.svg';
import wormchainIcon from '../images/wormchain.svg';
import xplaIcon from '../images/xpla.svg';
import { Chain, Network } from '@wormhole-foundation/sdk-base';

export const WORMCHAIN_URL = 'https://tncnt-eu-wormchain-main-01.rpc.p2p.world';
export const TESTNET_WORMCHAIN_URL = `https://corsproxy.io/?${encodeURIComponent(
Expand Down Expand Up @@ -176,45 +175,3 @@ export const GUARDIAN_SET_3 = [
name: 'Staking Facilities',
},
];

export const SUPPORTED_EVM_CHAINS: Record<string, Chain[]> = {
Testnet: ['Sepolia', 'ArbitrumSepolia', 'BaseSepolia', 'OptimismSepolia'],
Mainnet: [],
Devnet: [],
};

export const NTT_TOKENS: { [key in Network]: { [key in Chain]?: string } } = {
Mainnet: {},
Testnet: {
Solana: '87r5ZS91Q2pQbFTvvneqs7y7mbtegtqMt4LDAS4g23Ax',
Sepolia: '0x1d30E78B7C7fbbcef87ae6e97B5389b2e470CA4a',
ArbitrumSepolia: '0x84A1Cb660B19eB0063EE5FD377eC14AAe3364d74',
BaseSepolia: '0x7f430D4e7939D994C0955A01FC75D9DE33F12D11',
OptimismSepolia: '0x0e15979a7a1eFAEf20312CA45A59eb141bF7E340',
},
Devnet: {},
};

export const NTT_MANAGER_CONTRACT: { [key in Network]: { [key in Chain]?: string } } = {
Mainnet: {},
Testnet: {
Solana: 'nTTh3bZ5Aer6xboWZe39RDEft4MeVxSQ8D1EYAVLZw9',
Sepolia: '0xB231aD95f2301bc82eA44c515001F0F746D637e0',
ArbitrumSepolia: '0xEec94CD3083e067398256a79CcA7e740C5c8ef81',
BaseSepolia: '0xB03b030b2f5B40819Df76467d67eD1C85Ff66fAD',
OptimismSepolia: '0x7f430D4e7939D994C0955A01FC75D9DE33F12D11',
},
Devnet: {},
};

export const NTT_TRANSCEIVER_CONTRACT: { [key in Network]: { [key in Chain]?: string } } = {
Mainnet: {},
Testnet: {
Solana: '9WNzy7xYZyL2k6JnE9dWSp7VpYkvfRN3Rhd8wHv9J9mY',
Sepolia: '0x1fDC902e30b188FD2BA976B421Cb179943F57896',
ArbitrumSepolia: '0x0E24D17D7467467b39Bf64A9DFf88776Bd6c74d7',
BaseSepolia: '0x1e072169541f1171e427Aa44B5fd8924BEE71b0e',
OptimismSepolia: '0x41265eb2863bf0238081F6AeefeF73549C82C3DD',
},
Devnet: {},
};
Loading

0 comments on commit 7ec332d

Please sign in to comment.