Skip to content

Commit 41df34b

Browse files
panoelevan-gray
authored andcommitted
common/watcher: convert CONTRACTS
1 parent 5952601 commit 41df34b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1191
-531
lines changed

cloud_functions/src/alarmMissingVaas.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { ChainId } from '@wormhole-foundation/sdk-base';
1+
import { ChainId, Network } from '@wormhole-foundation/sdk-base';
22
import {
3-
Environment,
43
MISS_THRESHOLD_IN_MINS,
54
explorerBlock,
65
explorerTx,
7-
getEnvironment,
6+
getNetwork,
87
} from '@wormhole-foundation/wormhole-monitor-common';
98
import { chainIdToName } from '@wormhole-foundation/wormhole-monitor-common';
109
import { Firestore } from 'firebase-admin/firestore';
@@ -41,7 +40,7 @@ interface GovernedVAA {
4140
// The key is the vaaKey
4241
type GovernedVAAMap = Map<string, GovernedVAA>;
4342

44-
const network: Environment = getEnvironment();
43+
const network: Network = getNetwork();
4544

4645
export async function alarmMissingVaas(req: any, res: any) {
4746
res.set('Access-Control-Allow-Origin', '*');
@@ -119,7 +118,7 @@ export async function alarmMissingVaas(req: any, res: any) {
119118
console.log(`skipping over ${vaaKey} because it is governed`);
120119
continue;
121120
}
122-
if (await isVAASigned(getEnvironment(), vaaKey)) {
121+
if (await isVAASigned(getNetwork(), vaaKey)) {
123122
console.log(`skipping over ${vaaKey} because it is signed`);
124123
continue;
125124
}
@@ -131,7 +130,7 @@ export async function alarmMissingVaas(req: any, res: any) {
131130
txhash: msg.txHash,
132131
vaaKey: vaaKey,
133132
});
134-
if (network === 'mainnet') {
133+
if (network === 'Mainnet') {
135134
alarmSlackInfo.msg = formatMessage(msg);
136135
await formatAndSendToSlack(alarmSlackInfo);
137136
}
@@ -251,7 +250,7 @@ async function getAndProcessReobsVAAs(): Promise<Map<string, ReobserveInfo>> {
251250
if (data) {
252251
const vaas: ReobserveInfo[] = data.VAAs;
253252
vaas.forEach(async (vaa) => {
254-
if (!(await isVAASigned(getEnvironment(), vaa.vaaKey))) {
253+
if (!(await isVAASigned(getNetwork(), vaa.vaaKey))) {
255254
console.log('keeping reobserved VAA in firestore', vaa.vaaKey);
256255
current.set(vaa.txhash, vaa);
257256
} else {

cloud_functions/src/getReobserveVaas.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CHAIN_ID_SOLANA } from '@certusone/wormhole-sdk';
22
import { Connection } from '@solana/web3.js';
33
import { contracts } from '@wormhole-foundation/sdk-base';
44
import {
5-
getEnvironment,
5+
getNetwork,
66
isLegacyMessage,
77
normalizeCompileInstruction,
88
} from '@wormhole-foundation/wormhole-monitor-common';
@@ -133,7 +133,7 @@ async function getAndProcessReobsVAAs(): Promise<Map<string, ReobserveInfo>> {
133133
return current;
134134
}
135135
for (const vaa of realVaas) {
136-
if (!(await isVAASigned(getEnvironment(), vaa.vaaKey))) {
136+
if (!(await isVAASigned(getNetwork(), vaa.vaaKey))) {
137137
current.set(vaa.txhash, vaa);
138138
}
139139
}

cloud_functions/src/utils.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from 'axios';
22
import { PagerDutyInfo, SlackInfo } from './types';
3-
import { Environment } from '@wormhole-foundation/wormhole-monitor-common';
3+
import { Network } from '@wormhole-foundation/sdk-base';
44

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

90-
export async function isVAASigned(env: Environment, vaaKey: string): Promise<boolean> {
91-
const url: string = WormholescanRPC + 'v1/signed_vaa/' + vaaKey + '?network=' + env.toUpperCase();
90+
export async function isVAASigned(network: Network, vaaKey: string): Promise<boolean> {
91+
const url: string =
92+
WormholescanRPC + 'v1/signed_vaa/' + vaaKey + '?network=' + network.toUpperCase();
9293
try {
9394
const response = await axios.get(url);
9495
// curl -X 'GET' \

common/src/consts.ts

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
import { Chain, ChainId, chainToChainId, toChain, toChainId } from '@wormhole-foundation/sdk-base';
1+
import { Chain, ChainId, Network, chainToChainId, toChain } from '@wormhole-foundation/sdk-base';
22

3-
export type Environment = 'mainnet' | 'testnet' | 'devnet';
4-
export type Network = {
5-
env: Environment;
6-
endpoint: string;
7-
name: string;
8-
logo: string;
9-
type: 'guardian' | 'cloudfunction';
10-
};
113
export type Mode = 'vaa' | 'ntt';
124

135
export const MISS_THRESHOLD_IN_MINS = 40;
146
export const MISS_THRESHOLD_LABEL = '40 minutes';
157

168
export const INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
17-
[key in Environment]: { [key in Chain]?: string };
9+
[key in Network]: { [key in Chain]?: string };
1810
} = {
19-
['mainnet']: {
11+
['Mainnet']: {
2012
Ethereum: '12959638',
2113
Terra: '4810000', // not sure exactly but this should be before the first known message
2214
Bsc: '9745450',
@@ -43,7 +35,7 @@ export const INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
4335
Sei: '238594',
4436
Wormchain: '4510119', // https://bigdipper.live/wormhole/transactions/4D861F1BE86325D227FA006CA2745BBC6748AF5B5E0811DE536D02792928472A },
4537
},
46-
['testnet']: {
38+
['Testnet']: {
4739
Ethereum: '0',
4840
Terra: '0',
4941
Bsc: '0',
@@ -71,21 +63,21 @@ export const INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
7163
Wormchain: '0',
7264
PolygonSepolia: '2379275',
7365
},
74-
['devnet']: {},
66+
['Devnet']: {},
7567
};
7668

7769
export const INITIAL_NTT_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
78-
[key in Environment]: { [key in Chain]?: string };
70+
[key in Network]: { [key in Chain]?: string };
7971
} = {
80-
['mainnet']: {},
81-
['testnet']: {
72+
['Mainnet']: {},
73+
['Testnet']: {
8274
Solana: '285100152',
8375
Sepolia: '5472203',
8476
ArbitrumSepolia: '22501243',
8577
BaseSepolia: '7249669',
8678
OptimismSepolia: '9232548',
8779
},
88-
['devnet']: {},
80+
['Devnet']: {},
8981
};
9082

9183
export const TOKEN_BRIDGE_EMITTERS: { [key in Chain]?: string } = {

common/src/explorer.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {
22
ChainId,
3+
Network,
34
chainIdToChain,
45
chainToChainId,
56
chainToPlatform,
67
} from '@wormhole-foundation/sdk-base';
78
import base58 from 'bs58';
89
import { Buffer } from 'buffer';
9-
import { Environment } from './consts';
1010

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

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

214-
export const getExplorerTxHash = (_: Environment, chain: ChainId, txHash: string) => {
214+
export const getExplorerTxHash = (_: Network, chain: ChainId, txHash: string) => {
215215
let explorerTxHash = '';
216216
const platform = chainToPlatform(chainIdToChain(chain));
217217
if (platform === 'Cosmwasm') {

common/src/utils.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Environment, Mode } from './consts';
1+
import { Network } from '@wormhole-foundation/sdk-base';
2+
import { Mode } from './consts';
23

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

19-
export function getEnvironment(): Environment {
20+
export function getNetwork(): Network {
2021
const network: string = assertEnvironmentVariable('NETWORK').toLowerCase();
21-
if (network === 'mainnet' || network === 'testnet' || network === 'devnet') {
22-
return network;
22+
if (network === 'mainnet') {
23+
return 'Mainnet';
24+
}
25+
if (network === 'testnet') {
26+
return 'Testnet';
27+
}
28+
if (network === 'devnet') {
29+
return 'Devnet';
2330
}
2431
throw new Error(`Unknown network: ${network}`);
2532
}

dashboard/src/components/Alerts.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const getBehindDiffForChain = (chainId: number) =>
3131
isLayer2(chainId) ? BEHIND_DIFF * 2 : BEHIND_DIFF;
3232

3333
export const getNumGuardians = (environment: Environment) =>
34-
environment === 'mainnet' ? GUARDIAN_SET_3.length : 1;
34+
environment === 'Mainnet' ? GUARDIAN_SET_3.length : 1;
3535

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

0 commit comments

Comments
 (0)