Skip to content

Commit

Permalink
common/watcher: convert CONTRACTS
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel authored and evan-gray committed Apr 5, 2024
1 parent 5952601 commit 41df34b
Show file tree
Hide file tree
Showing 62 changed files with 1,191 additions and 531 deletions.
13 changes: 6 additions & 7 deletions cloud_functions/src/alarmMissingVaas.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ChainId } from '@wormhole-foundation/sdk-base';
import { ChainId, Network } from '@wormhole-foundation/sdk-base';
import {
Environment,
MISS_THRESHOLD_IN_MINS,
explorerBlock,
explorerTx,
getEnvironment,
getNetwork,
} from '@wormhole-foundation/wormhole-monitor-common';
import { chainIdToName } from '@wormhole-foundation/wormhole-monitor-common';
import { Firestore } from 'firebase-admin/firestore';
Expand Down Expand Up @@ -41,7 +40,7 @@ interface GovernedVAA {
// The key is the vaaKey
type GovernedVAAMap = Map<string, GovernedVAA>;

const network: Environment = getEnvironment();
const network: Network = getNetwork();

export async function alarmMissingVaas(req: any, res: any) {
res.set('Access-Control-Allow-Origin', '*');
Expand Down Expand Up @@ -119,7 +118,7 @@ export async function alarmMissingVaas(req: any, res: any) {
console.log(`skipping over ${vaaKey} because it is governed`);
continue;
}
if (await isVAASigned(getEnvironment(), vaaKey)) {
if (await isVAASigned(getNetwork(), vaaKey)) {
console.log(`skipping over ${vaaKey} because it is signed`);
continue;
}
Expand All @@ -131,7 +130,7 @@ export async function alarmMissingVaas(req: any, res: any) {
txhash: msg.txHash,
vaaKey: vaaKey,
});
if (network === 'mainnet') {
if (network === 'Mainnet') {
alarmSlackInfo.msg = formatMessage(msg);
await formatAndSendToSlack(alarmSlackInfo);
}
Expand Down Expand Up @@ -251,7 +250,7 @@ async function getAndProcessReobsVAAs(): Promise<Map<string, ReobserveInfo>> {
if (data) {
const vaas: ReobserveInfo[] = data.VAAs;
vaas.forEach(async (vaa) => {
if (!(await isVAASigned(getEnvironment(), vaa.vaaKey))) {
if (!(await isVAASigned(getNetwork(), vaa.vaaKey))) {
console.log('keeping reobserved VAA in firestore', vaa.vaaKey);
current.set(vaa.txhash, vaa);
} else {
Expand Down
4 changes: 2 additions & 2 deletions cloud_functions/src/getReobserveVaas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CHAIN_ID_SOLANA } from '@certusone/wormhole-sdk';
import { Connection } from '@solana/web3.js';
import { contracts } from '@wormhole-foundation/sdk-base';
import {
getEnvironment,
getNetwork,
isLegacyMessage,
normalizeCompileInstruction,
} from '@wormhole-foundation/wormhole-monitor-common';
Expand Down Expand Up @@ -133,7 +133,7 @@ async function getAndProcessReobsVAAs(): Promise<Map<string, ReobserveInfo>> {
return current;
}
for (const vaa of realVaas) {
if (!(await isVAASigned(getEnvironment(), vaa.vaaKey))) {
if (!(await isVAASigned(getNetwork(), vaa.vaaKey))) {
current.set(vaa.txhash, vaa);
}
}
Expand Down
7 changes: 4 additions & 3 deletions cloud_functions/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import { PagerDutyInfo, SlackInfo } from './types';
import { Environment } from '@wormhole-foundation/wormhole-monitor-common';
import { Network } from '@wormhole-foundation/sdk-base';

export async function sleep(timeout: number) {
return new Promise((resolve) => setTimeout(resolve, timeout));
Expand Down Expand Up @@ -87,8 +87,9 @@ export async function formatAndSendToSlack(info: SlackInfo): Promise<any> {
return responseData;
}

export async function isVAASigned(env: Environment, vaaKey: string): Promise<boolean> {
const url: string = WormholescanRPC + 'v1/signed_vaa/' + vaaKey + '?network=' + env.toUpperCase();
export async function isVAASigned(network: Network, vaaKey: string): Promise<boolean> {
const url: string =
WormholescanRPC + 'v1/signed_vaa/' + vaaKey + '?network=' + network.toUpperCase();
try {
const response = await axios.get(url);
// curl -X 'GET' \
Expand Down
26 changes: 9 additions & 17 deletions common/src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { Chain, ChainId, chainToChainId, toChain, toChainId } from '@wormhole-foundation/sdk-base';
import { Chain, ChainId, Network, chainToChainId, toChain } from '@wormhole-foundation/sdk-base';

export type Environment = 'mainnet' | 'testnet' | 'devnet';
export type Network = {
env: Environment;
endpoint: string;
name: string;
logo: string;
type: 'guardian' | 'cloudfunction';
};
export type Mode = 'vaa' | 'ntt';

export const MISS_THRESHOLD_IN_MINS = 40;
export const MISS_THRESHOLD_LABEL = '40 minutes';

export const INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
[key in Environment]: { [key in Chain]?: string };
[key in Network]: { [key in Chain]?: string };
} = {
['mainnet']: {
['Mainnet']: {
Ethereum: '12959638',
Terra: '4810000', // not sure exactly but this should be before the first known message
Bsc: '9745450',
Expand All @@ -43,7 +35,7 @@ export const INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
Sei: '238594',
Wormchain: '4510119', // https://bigdipper.live/wormhole/transactions/4D861F1BE86325D227FA006CA2745BBC6748AF5B5E0811DE536D02792928472A },
},
['testnet']: {
['Testnet']: {
Ethereum: '0',
Terra: '0',
Bsc: '0',
Expand Down Expand Up @@ -71,21 +63,21 @@ export const INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
Wormchain: '0',
PolygonSepolia: '2379275',
},
['devnet']: {},
['Devnet']: {},
};

export const INITIAL_NTT_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
[key in Environment]: { [key in Chain]?: string };
[key in Network]: { [key in Chain]?: string };
} = {
['mainnet']: {},
['testnet']: {
['Mainnet']: {},
['Testnet']: {
Solana: '285100152',
Sepolia: '5472203',
ArbitrumSepolia: '22501243',
BaseSepolia: '7249669',
OptimismSepolia: '9232548',
},
['devnet']: {},
['Devnet']: {},
};

export const TOKEN_BRIDGE_EMITTERS: { [key in Chain]?: string } = {
Expand Down
12 changes: 6 additions & 6 deletions common/src/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
ChainId,
Network,
chainIdToChain,
chainToChainId,
chainToPlatform,
} from '@wormhole-foundation/sdk-base';
import base58 from 'bs58';
import { Buffer } from 'buffer';
import { Environment } from './consts';

export const explorerBlock = (network: Environment, chainId: ChainId, block: string) =>
network === 'mainnet'
export const explorerBlock = (network: Network, chainId: ChainId, block: string) =>
network === 'Mainnet'
? chainId === chainToChainId('Solana')
? `https://solana.fm/block/${block}`
: chainId === chainToChainId('Ethereum')
Expand Down Expand Up @@ -107,8 +107,8 @@ export const explorerBlock = (network: Environment, chainId: ChainId, block: str
: // : chainId === chainToChainId('Wormscan') <-- not supported on testnet dashboard
'';

export const explorerTx = (network: Environment, chainId: ChainId, tx: string) =>
network === 'mainnet'
export const explorerTx = (network: Network, chainId: ChainId, tx: string) =>
network === 'Mainnet'
? chainId === chainToChainId('Solana')
? `https://solana.fm/tx/${tx}`
: chainId === chainToChainId('Ethereum')
Expand Down Expand Up @@ -211,7 +211,7 @@ export const explorerVaa = (network: string, key: string) =>
? `https://wormholescan.io/#/tx/${key}`
: `https://wormholescan.io/#/tx/${key}?network=TESTNET`;

export const getExplorerTxHash = (_: Environment, chain: ChainId, txHash: string) => {
export const getExplorerTxHash = (_: Network, chain: ChainId, txHash: string) => {
let explorerTxHash = '';
const platform = chainToPlatform(chainIdToChain(chain));
if (platform === 'Cosmwasm') {
Expand Down
15 changes: 11 additions & 4 deletions common/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Environment, Mode } from './consts';
import { Network } from '@wormhole-foundation/sdk-base';
import { Mode } from './consts';

export async function sleep(timeout: number) {
return new Promise((resolve) => setTimeout(resolve, timeout));
Expand All @@ -16,10 +17,16 @@ export const padUint64 = (s: string): string => s.padStart(MAX_UINT_64.length, '
export const makeSignedVAAsRowKey = (chain: number, emitter: string, sequence: string): string =>
`${padUint16(chain.toString())}/${emitter}/${padUint64(sequence)}`;

export function getEnvironment(): Environment {
export function getNetwork(): Network {
const network: string = assertEnvironmentVariable('NETWORK').toLowerCase();
if (network === 'mainnet' || network === 'testnet' || network === 'devnet') {
return network;
if (network === 'mainnet') {
return 'Mainnet';
}
if (network === 'testnet') {
return 'Testnet';
}
if (network === 'devnet') {
return 'Devnet';
}
throw new Error(`Unknown network: ${network}`);
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/components/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const getBehindDiffForChain = (chainId: number) =>
isLayer2(chainId) ? BEHIND_DIFF * 2 : BEHIND_DIFF;

export const getNumGuardians = (environment: Environment) =>
environment === 'mainnet' ? GUARDIAN_SET_3.length : 1;
environment === 'Mainnet' ? GUARDIAN_SET_3.length : 1;

export function getQuorumCount(environment: Environment): number {
return Math.floor((getNumGuardians(environment) * 2) / 3 + 1);
Expand Down
Loading

0 comments on commit 41df34b

Please sign in to comment.