Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watcher: add berachain and snaxchain #351

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions cloud_functions/src/computeNTTRateLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import {
getSolanaTokenDecimals,
NTTRateLimit,
getNetwork,
NTTEvmChain,
NTTChain,
nttChains,
} from '@wormhole-foundation/wormhole-monitor-common';
import { EvmPlatform, EvmChains } from '@wormhole-foundation/sdk-evm';
import { EvmPlatform } from '@wormhole-foundation/sdk-evm';
import { SolanaPlatform } from '@wormhole-foundation/sdk-solana';
import { EvmNtt } from '@wormhole-foundation/sdk-evm-ntt';
import { SolanaNtt } from '@wormhole-foundation/sdk-solana-ntt';
import { Network, Chain, contracts, rpc, chainToChainId } from '@wormhole-foundation/sdk-base';
import { Network, contracts, rpc, chainToChainId } from '@wormhole-foundation/sdk-base';
import { Storage } from '@google-cloud/storage';

const storage = new Storage();
Expand All @@ -29,11 +32,11 @@ const cloudStorageCache = cacheBucket.file(cacheFileName);
async function computeNTTRateLimits_(
network: Network,
token: string,
chain: Chain
chain: NTTChain
): Promise<NTTRateLimit> {
let ntt: EvmNtt<Network, EvmChains> | SolanaNtt<Network, 'Solana'>;
let ntt: EvmNtt<Network, NTTEvmChain> | SolanaNtt<Network, 'Solana'>;
let tokenDecimals: number;
const rpcEndpoint = rpc.rpcAddress(network, chain as Chain);
const rpcEndpoint = rpc.rpcAddress(network, chain);
const tokenAddress = NTT_TOKENS[network][token][chain]!;
const managerContract = NTT_MANAGER_CONTRACT[network][token][chain]!;
const transceiverContract = NTT_TRANSCEIVER_CONTRACT[network][token][chain]!;
Expand All @@ -52,7 +55,7 @@ async function computeNTTRateLimits_(
});
tokenDecimals = await getSolanaTokenDecimals(rpcEndpoint, tokenAddress);
} else {
const evmChain = chain as EvmChains;
const evmChain = chain;
const platform = new EvmPlatform(network);
ntt = new EvmNtt(network, evmChain, platform.getRpc(evmChain), {
ntt: {
Expand Down Expand Up @@ -120,10 +123,8 @@ export async function computeNTTRateLimits(req: any, res: any) {

const rateLimits = await Promise.all(
Object.entries(managerContracts).map(async ([token, manager]) => {
const inboundCapacityPromises = Object.entries(manager)
.map(([chain, contract]) =>
contract ? computeNTTRateLimits_(network, token, chain as Chain) : null
)
const inboundCapacityPromises = nttChains
.map((chain) => (manager[chain] ? computeNTTRateLimits_(network, token, chain) : null))
.filter(Boolean);

const inboundCapacity = await Promise.all(inboundCapacityPromises);
Expand Down
18 changes: 11 additions & 7 deletions cloud_functions/src/computeTotalSupplyAndLocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {
getEvmTotalSupply,
getNetwork,
normalizeToDecimals,
nttChains,
} from '@wormhole-foundation/wormhole-monitor-common';
import { PublicKey } from '@solana/web3.js';
import { Network, rpc, Chain, chainToChainId } from '@wormhole-foundation/sdk-base';
import { Network, rpc, chainToChainId } from '@wormhole-foundation/sdk-base';
import { Storage } from '@google-cloud/storage';

const storage = new Storage();
Expand All @@ -38,21 +39,24 @@ async function fetchTotalSupplyAndLocked(network: Network): Promise<NTTTotalSupp

const evmTotalSupply: NTTTotalSupplyAndLockedData[] = [];
let cumulativeEvmSupply = 0n;
for (const [supportedChain] of Object.entries(NTT_TOKENS[network][token])) {
for (const supportedChain of nttChains) {
const tokenContract = NTT_TOKENS[network][token][supportedChain];
const managerContract = NTT_MANAGER_CONTRACT[network][token][supportedChain];
if (!tokenContract || !managerContract) continue;
if (supportedChain === 'Solana') continue;
const tokenSupply = await getEvmTotalSupply(
rpc.rpcAddress(network, supportedChain as Chain),
NTT_TOKENS[network][token][supportedChain as Chain]!
rpc.rpcAddress(network, supportedChain),
tokenContract
);

const tokenDecimals = await getEvmTokenDecimals(
rpc.rpcAddress(network, supportedChain as Chain),
NTT_MANAGER_CONTRACT[network][token][supportedChain as Chain]!
rpc.rpcAddress(network, supportedChain),
managerContract
);

evmTotalSupply.push({
tokenName: token,
chain: chainToChainId(supportedChain as Chain),
chain: chainToChainId(supportedChain),
totalSupply: {
amount: tokenSupply.toString(),
decimals: tokenDecimals,
Expand Down
1 change: 1 addition & 0 deletions common/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: NetworkChainBlockMap
Sei: '0',
Wormchain: '4495661',
PolygonSepolia: '2379275',
Berachain: '1473347',
},
['Devnet']: {},
};
Expand Down
45 changes: 32 additions & 13 deletions common/src/nttConsts.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
import { Chain, Network, chains } from '@wormhole-foundation/sdk-base';
import { Network, networks } from '@wormhole-foundation/sdk-base';
import { EvmChains } from '@wormhole-foundation/sdk-evm';

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

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

export const nttChains = [
'Ethereum',
'Fantom',
'Solana',
'Arbitrum',
'Optimism',
'Base',
'Sepolia',
'ArbitrumSepolia',
'BaseSepolia',
'OptimismSepolia',
'Holesky',
] as const;

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

for (const network in nttManagerContract) {
nttContract[network as Network] = {};
for (const network of networks) {
nttContract[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];
for (const tokenName in nttManagerContract[network]) {
for (const chain of nttChains) {
const tokenAddress = nttManagerContract[network][tokenName][chain];

if (tokenAddress) {
if (!nttContract[network as Network][chain as Chain]) {
nttContract[network as Network][chain as Chain] = [];
if (!nttContract[network][chain]) {
nttContract[network][chain] = [];
}
nttContract[network as Network][chain as Chain]!.push(tokenAddress);
nttContract[network][chain]!.push(tokenAddress);
}
}
}
Expand Down Expand Up @@ -113,14 +128,18 @@ export const NTT_TOKENS: NTTContract = {
Devnet: {},
};

export type NTTChain = (typeof nttChains)[number];

export type NTTEvmChain = NTTChain & EvmChains;

export const NTT_MANAGER_CONTRACT_ARRAY =
convertNTTManagerContractToNTTContractArray(NTT_MANAGER_CONTRACT);

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

return chains.filter((chain) => chain in contractDetails);
return nttChains.filter((chain) => chain in contractDetails);
}
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/node": "^18.6.4",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@wormhole-foundation/sdk-icons": "^0.6.6-beta.1",
"@wormhole-foundation/sdk-icons": "^0.9.1",
"buffer": "^6.0.3",
"numeral": "^2.0.6",
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@injectivelabs/sdk-ts": "^1.0.368",
"@mysten/sui.js": "^0.50.1",
"@terra-money/terra.js": "^3.1.3",
"@wormhole-foundation/sdk": "^0.8.0",
"@wormhole-foundation/sdk": "^0.9.1",
"@xpla/xpla.js": "^0.2.3",
"aptos": "1.5.0",
"dotenv": "^16.0.3",
Expand Down
Loading
Loading