Skip to content

Commit 6963a78

Browse files
committed
common: audit toChain usage
1 parent 7ab95c7 commit 6963a78

19 files changed

+189
-191
lines changed

cloud_functions/src/alarmMissingVaas.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { ChainId, toChain } from '@wormhole-foundation/sdk-base';
2-
import { MissingVaasByChain, commonGetMissingVaas } from './getMissingVaas';
3-
import { assertEnvironmentVariable, formatAndSendToSlack, isVAASigned } from './utils';
4-
import { ObservedMessage, ReobserveInfo, SlackInfo } from './types';
1+
import { ChainId } from '@wormhole-foundation/sdk-base';
52
import {
63
Environment,
7-
getEnvironment,
4+
MISS_THRESHOLD_IN_MINS,
85
explorerBlock,
96
explorerTx,
10-
MISS_THRESHOLD_IN_MINS,
7+
getEnvironment,
118
} from '@wormhole-foundation/wormhole-monitor-common';
9+
import chainIdToName from '@wormhole-foundation/wormhole-monitor-common/src/chainIdToName';
1210
import { Firestore } from 'firebase-admin/firestore';
11+
import { MissingVaasByChain, commonGetMissingVaas } from './getMissingVaas';
12+
import { ObservedMessage, ReobserveInfo, SlackInfo } from './types';
13+
import { assertEnvironmentVariable, formatAndSendToSlack, isVAASigned } from './utils';
1314

1415
interface EnqueuedVAAResponse {
1516
sequence: string;
@@ -290,7 +291,7 @@ function convert(msg: ObservedMessage): FirestoreVAA {
290291
}
291292

292293
function formatMessage(msg: ObservedMessage): string {
293-
const cName: string = toChain(msg.chain);
294+
const cName: string = chainIdToName(msg.chain);
294295
const vaaKeyUrl: string = `https://wormholescan.io/#/tx/${msg.chain}/${msg.emitter}/${msg.seq}`;
295296
const txHashUrl: string = explorerTx(network, msg.chain as ChainId, msg.txHash);
296297
const blockUrl: string = explorerBlock(network, msg.chain as ChainId, msg.block.toString());
@@ -351,7 +352,7 @@ async function alarmOldBlockTimes(latestTimes: LatestTimeByChain): Promise<void>
351352
if (latestTime < oneDayAgo && !alarmedChains.has(chainId)) {
352353
// Send a message to slack
353354
const chainTime: Date = new Date(latestTime);
354-
const cName: string = toChain(chainId);
355+
const cName: string = chainIdToName(chainId);
355356
const deltaTime: number = (now.getTime() - chainTime.getTime()) / (1000 * 60 * 60 * 24);
356357
alarmSlackInfo.msg = `*Chain:* ${cName}(${chainId})\nThe ${network} watcher is behind by ${deltaTime} days.`;
357358
await formatAndSendToSlack(alarmSlackInfo);

cloud_functions/src/processVaa.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
CircleIntegrationPayload,
2828
parseCircleIntegrationDepositWithPayload,
2929
} from './_sdk_circleIntegration';
30-
import { ChainId } from '@wormhole-foundation/sdk-base';
30+
import { ChainId, toChainId } from '@wormhole-foundation/sdk-base';
3131

3232
let initialized = false;
3333
let bigtable: Bigtable;
@@ -70,8 +70,7 @@ export const processVaa: EventFunction = async (message: PubsubMessage, context:
7070
return;
7171
}
7272
const [chain, emitter] = rowKey.split('/');
73-
const chainId = Number(chain) as ChainId;
74-
assertChain(chainId);
73+
const chainId = toChainId(Number(chain));
7574
const module = isTokenBridgeEmitter(chainId, emitter)
7675
? 'TokenBridge'
7776
: isCircleIntegrationEmitter(chainId, emitter)
File renamed without changes.

common/src/consts.ts

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

33
export type Environment = 'mainnet' | 'testnet' | 'devnet';
44
export type Network = {
@@ -157,12 +157,12 @@ export const isCircleIntegrationEmitter = (chain: ChainId | Chain, emitter: stri
157157

158158
// https://developers.circle.com/stablecoins/docs/supported-domains
159159
export const CIRCLE_DOMAIN_TO_CHAIN_ID: { [key: number]: ChainId } = {
160-
0: toChainId('Ethereum'),
161-
1: toChainId('Avalanche'),
162-
2: toChainId('Optimism'),
163-
3: toChainId('Arbitrum'),
164-
6: toChainId('Base'),
165-
7: toChainId('Polygon'),
160+
0: chainToChainId('Ethereum'),
161+
1: chainToChainId('Avalanche'),
162+
2: chainToChainId('Optimism'),
163+
3: chainToChainId('Arbitrum'),
164+
6: chainToChainId('Base'),
165+
7: chainToChainId('Polygon'),
166166
};
167167

168168
export const JUMP_GUARDIAN_ADDRESS = '58cc3ae5c097b213ce3c81979e1b9f9570746aa5';

common/src/explorer.ts

+106-101
Original file line numberDiff line numberDiff line change
@@ -1,203 +1,208 @@
1-
import { ChainId, chainIdToChain, chainToPlatform, toChainId } from '@wormhole-foundation/sdk-base';
1+
import {
2+
ChainId,
3+
chainIdToChain,
4+
chainToChainId,
5+
chainToPlatform,
6+
} from '@wormhole-foundation/sdk-base';
27
import { base58 } from 'ethers/lib/utils';
38
import { Environment } from './consts';
49

510
export const explorerBlock = (network: Environment, chainId: ChainId, block: string) =>
611
network === 'mainnet'
7-
? chainId === toChainId('Solana')
12+
? chainId === chainToChainId('Solana')
813
? `https://solana.fm/block/${block}`
9-
: chainId === toChainId('Ethereum')
14+
: chainId === chainToChainId('Ethereum')
1015
? `https://etherscan.io/block/${block}`
11-
: chainId === toChainId('Terra')
16+
: chainId === chainToChainId('Terra')
1217
? `https://finder.terra.money/columbus-5/block/${block}`
13-
: chainId === toChainId('Bsc')
18+
: chainId === chainToChainId('Bsc')
1419
? `https://bscscan.com/block/${block}`
15-
: chainId === toChainId('Polygon')
20+
: chainId === chainToChainId('Polygon')
1621
? `https://polygonscan.com/block/${block}`
17-
: chainId === toChainId('Avalanche')
22+
: chainId === chainToChainId('Avalanche')
1823
? `https://snowtrace.io/block/${block}`
19-
: chainId === toChainId('Oasis')
24+
: chainId === chainToChainId('Oasis')
2025
? `https://explorer.emerald.oasis.dev/block/${block}`
21-
: chainId === toChainId('Algorand')
26+
: chainId === chainToChainId('Algorand')
2227
? `https://app.dappflow.org/explorer/block/${block}`
23-
: chainId === toChainId('Fantom')
28+
: chainId === chainToChainId('Fantom')
2429
? `https://ftmscan.com/block/${block}`
25-
: chainId === toChainId('Karura')
30+
: chainId === chainToChainId('Karura')
2631
? `https://blockscout.karura.network/block/${block}`
27-
: chainId === toChainId('Acala')
32+
: chainId === chainToChainId('Acala')
2833
? `https://blockscout.acala.network/block/${block}`
29-
: chainId === toChainId('Klaytn')
34+
: chainId === chainToChainId('Klaytn')
3035
? `https://scope.klaytn.com/block/${block}`
31-
: chainId === toChainId('Celo')
36+
: chainId === chainToChainId('Celo')
3237
? `https://explorer.celo.org/block/${block}`
33-
: chainId === toChainId('Near')
38+
: chainId === chainToChainId('Near')
3439
? `https://nearblocks.io/blocks/${block}`
35-
: chainId === toChainId('Moonbeam')
40+
: chainId === chainToChainId('Moonbeam')
3641
? `https://moonscan.io/block/${block}`
37-
: chainId === toChainId('Terra2')
42+
: chainId === chainToChainId('Terra2')
3843
? `https://finder.terra.money/phoenix-1/block/${block}`
39-
: chainId === toChainId('Injective')
44+
: chainId === chainToChainId('Injective')
4045
? `https://explorer.injective.network/block/${block}`
41-
: chainId === toChainId('Sui')
46+
: chainId === chainToChainId('Sui')
4247
? `https://suiexplorer.com/checkpoint/${block}`
43-
: chainId === toChainId('Aptos')
48+
: chainId === chainToChainId('Aptos')
4449
? `https://explorer.aptoslabs.com/block/${block}`
45-
: chainId === toChainId('Arbitrum')
50+
: chainId === chainToChainId('Arbitrum')
4651
? `https://arbiscan.io/block/${block}`
47-
: chainId === toChainId('Optimism')
52+
: chainId === chainToChainId('Optimism')
4853
? `https://optimistic.etherscan.io/block/${block}`
49-
: chainId === toChainId('Xpla')
54+
: chainId === chainToChainId('Xpla')
5055
? `https://explorer.xpla.io/mainnet/block/${block}`
51-
: chainId === toChainId('Base')
56+
: chainId === chainToChainId('Base')
5257
? `https://basescan.org/block/${block}`
53-
: chainId === toChainId('Sei')
58+
: chainId === chainToChainId('Sei')
5459
? `https://www.seiscan.app/pacific-1/blocks/${block}`
55-
: chainId === toChainId('Wormchain')
60+
: chainId === chainToChainId('Wormchain')
5661
? `https://bigdipper.live/wormhole/blocks/${block}`
5762
: ''
58-
: chainId === toChainId('Solana')
63+
: chainId === chainToChainId('Solana')
5964
? `https://explorer.solana.com/${block}?cluster=testnet`
60-
: chainId === toChainId('Ethereum')
65+
: chainId === chainToChainId('Ethereum')
6166
? `https://sepolia.etherscan.io/block/${block}`
62-
: // : chainId === toChainId('Terra') <-- not supported on testnet dashboard
63-
chainId === toChainId('Bsc')
67+
: // : chainId === chainToChainId('Terra') <-- not supported on testnet dashboard
68+
chainId === chainToChainId('Bsc')
6469
? `https://testnet.bscscan.com/block/${block}`
65-
: chainId === toChainId('Polygon')
70+
: chainId === chainToChainId('Polygon')
6671
? `https://mumbai.polygonscan.com/block/${block}`
67-
: chainId === toChainId('Avalanche')
72+
: chainId === chainToChainId('Avalanche')
6873
? `https://testnet.snowtrace.io/block/${block}`
69-
: chainId === toChainId('Oasis')
74+
: chainId === chainToChainId('Oasis')
7075
? `https://testnet.oasisscan.com/block/${block}`
71-
: chainId === toChainId('Algorand')
76+
: chainId === chainToChainId('Algorand')
7277
? `https://app.dappflow.org/explorer/block/${block}`
73-
: chainId === toChainId('Fantom')
78+
: chainId === chainToChainId('Fantom')
7479
? `https://testnet.ftmscan.com/block/${block}`
75-
: // : chainId === toChainId('Karura') <-- not supported on testnet dashboard
76-
chainId === toChainId('Acala')
80+
: // : chainId === chainToChainId('Karura') <-- not supported on testnet dashboard
81+
chainId === chainToChainId('Acala')
7782
? `https://blockscout.mandala.aca-staging.network/block/${block}`
78-
: chainId === toChainId('Klaytn')
83+
: chainId === chainToChainId('Klaytn')
7984
? `https://baobab.klaytnscope.com/block/${block}`
80-
: chainId === toChainId('Celo')
85+
: chainId === chainToChainId('Celo')
8186
? `https://alfajores.celoscan.io/block/${block}`
82-
: // : chainId === toChainId('Near') <-- not supported on testnet dashboard
83-
chainId === toChainId('Moonbeam')
87+
: // : chainId === chainToChainId('Near') <-- not supported on testnet dashboard
88+
chainId === chainToChainId('Moonbeam')
8489
? `https://moonbase.moonscan.io/block/${block}`
85-
: // : chainId === toChainId('Terra2') <-- not supported on testnet dashboard
86-
// : chainId === toChainId('Injective') <-- not supported on testnet dashboard
87-
chainId === toChainId('Sui')
90+
: // : chainId === chainToChainId('Terra2') <-- not supported on testnet dashboard
91+
// : chainId === chainToChainId('Injective') <-- not supported on testnet dashboard
92+
chainId === chainToChainId('Sui')
8893
? `https://suiexplorer.com/checkpoint/${block}?network=testnet`
89-
: chainId === toChainId('Aptos')
94+
: chainId === chainToChainId('Aptos')
9095
? `https://explorer.aptoslabs.com/block/${block}?network=testnet`
91-
: chainId === toChainId('Arbitrum')
96+
: chainId === chainToChainId('Arbitrum')
9297
? `https://sepolia.arbiscan.io/block/${block}`
93-
: chainId === toChainId('Optimism')
98+
: chainId === chainToChainId('Optimism')
9499
? `https://sepolia-optimism.etherscan.io/block/${block}`
95-
: chainId === toChainId('Xpla')
100+
: chainId === chainToChainId('Xpla')
96101
? `https://explorer.xpla.io/testnet/block/${block}`
97-
: chainId === toChainId('Base')
102+
: chainId === chainToChainId('Base')
98103
? `https://goerli.basescan.org/block/${block}`
99-
: chainId === toChainId('Sei')
104+
: chainId === chainToChainId('Sei')
100105
? `https://www.seiscan.app/atlantic-2/blocks/${block}`
101-
: // : chainId === toChainId('Wormscan') <-- not supported on testnet dashboard
106+
: // : chainId === chainToChainId('Wormscan') <-- not supported on testnet dashboard
102107
'';
103108

104109
export const explorerTx = (network: Environment, chainId: ChainId, tx: string) =>
105110
network === 'mainnet'
106-
? chainId === toChainId('Solana')
111+
? chainId === chainToChainId('Solana')
107112
? `https://solana.fm/tx/${tx}`
108-
: chainId === toChainId('Ethereum')
113+
: chainId === chainToChainId('Ethereum')
109114
? `https://etherscan.io/tx/${tx}`
110-
: chainId === toChainId('Terra')
115+
: chainId === chainToChainId('Terra')
111116
? `https://finder.terra.money/columbus-5/tx/${tx}`
112-
: chainId === toChainId('Bsc')
117+
: chainId === chainToChainId('Bsc')
113118
? `https://bscscan.com/tx/${tx}`
114-
: chainId === toChainId('Polygon')
119+
: chainId === chainToChainId('Polygon')
115120
? `https://polygonscan.com/tx/${tx}`
116-
: chainId === toChainId('Avalanche')
121+
: chainId === chainToChainId('Avalanche')
117122
? `https://snowtrace.io/tx/${tx}`
118-
: chainId === toChainId('Oasis')
123+
: chainId === chainToChainId('Oasis')
119124
? `https://explorer.emerald.oasis.dev/tx/${tx}`
120-
: chainId === toChainId('Algorand')
125+
: chainId === chainToChainId('Algorand')
121126
? `https://app.dappflow.org/explorer/transaction/${tx}`
122-
: chainId === toChainId('Fantom')
127+
: chainId === chainToChainId('Fantom')
123128
? `https://ftmscan.com/tx/${tx}`
124-
: chainId === toChainId('Karura')
129+
: chainId === chainToChainId('Karura')
125130
? `https://blockscout.karura.network/tx/${tx}`
126-
: chainId === toChainId('Acala')
131+
: chainId === chainToChainId('Acala')
127132
? `https://blockscout.acala.network/tx/${tx}`
128-
: chainId === toChainId('Klaytn')
133+
: chainId === chainToChainId('Klaytn')
129134
? `https://scope.klaytn.com/tx/${tx}`
130-
: chainId === toChainId('Celo')
135+
: chainId === chainToChainId('Celo')
131136
? `https://explorer.celo.org/tx/${tx}`
132-
: chainId === toChainId('Near')
137+
: chainId === chainToChainId('Near')
133138
? `https://explorer.near.org/transactions/${tx}`
134-
: chainId === toChainId('Moonbeam')
139+
: chainId === chainToChainId('Moonbeam')
135140
? `https://moonscan.io/tx/${tx}`
136-
: chainId === toChainId('Terra2')
141+
: chainId === chainToChainId('Terra2')
137142
? `https://finder.terra.money/phoenix-1/tx/${tx}`
138-
: chainId === toChainId('Injective')
143+
: chainId === chainToChainId('Injective')
139144
? `https://explorer.injective.network/transaction/${tx}`
140-
: chainId === toChainId('Sui')
145+
: chainId === chainToChainId('Sui')
141146
? `https://suiexplorer.com/txblock/${tx}`
142-
: chainId === toChainId('Aptos')
147+
: chainId === chainToChainId('Aptos')
143148
? `https://explorer.aptoslabs.com/txn/${tx}?network=mainnet`
144-
: chainId === toChainId('Arbitrum')
149+
: chainId === chainToChainId('Arbitrum')
145150
? `https://arbiscan.io/tx/${tx}`
146-
: chainId === toChainId('Optimism')
151+
: chainId === chainToChainId('Optimism')
147152
? `https://optimistic.etherscan.io/tx/${tx}`
148-
: chainId === toChainId('Xpla')
153+
: chainId === chainToChainId('Xpla')
149154
? `https://explorer.xpla.io/mainnet/tx/${tx}`
150-
: chainId === toChainId('Base')
155+
: chainId === chainToChainId('Base')
151156
? `https://basescan.org/tx/${tx}`
152-
: chainId === toChainId('Sei')
157+
: chainId === chainToChainId('Sei')
153158
? `https://www.seiscan.app/pacific-1/txs/${tx}`
154-
: chainId === toChainId('Wormchain')
159+
: chainId === chainToChainId('Wormchain')
155160
? `https://bigdipper.live/wormhole/transactions/${tx}`
156161
: ''
157-
: chainId === toChainId('Solana')
162+
: chainId === chainToChainId('Solana')
158163
? `https://solscan.io/txs/${tx}?cluster=testnet`
159-
: chainId === toChainId('Ethereum')
164+
: chainId === chainToChainId('Ethereum')
160165
? `https://sepolia.etherscan.io/tx/${tx}`
161-
: // : chainId === toChainId('Terra') <-- not supported on testnet dashboard
162-
chainId === toChainId('Bsc')
166+
: // : chainId === chainToChainId('Terra') <-- not supported on testnet dashboard
167+
chainId === chainToChainId('Bsc')
163168
? `https://testnet.bscscan.com/tx/${tx}`
164-
: chainId === toChainId('Polygon')
169+
: chainId === chainToChainId('Polygon')
165170
? `https://mumbai.polygonscan.com/tx/${tx}`
166-
: chainId === toChainId('Avalanche')
171+
: chainId === chainToChainId('Avalanche')
167172
? `https://testnet.snowtrace.io/tx/${tx}`
168-
: chainId === toChainId('Oasis')
173+
: chainId === chainToChainId('Oasis')
169174
? `https://testnet.oasisscan.com/tx/${tx}`
170-
: chainId === toChainId('Algorand')
175+
: chainId === chainToChainId('Algorand')
171176
? `https://app.dappflow.org/explorer/transaction/${tx}`
172-
: chainId === toChainId('Fantom')
177+
: chainId === chainToChainId('Fantom')
173178
? `https://testnet.ftmscan.com/tx/${tx}`
174-
: // chainId === toChainId('Karura') <-- not supported on testnet dashboard
175-
chainId === toChainId('Acala')
179+
: // chainId === chainToChainId('Karura') <-- not supported on testnet dashboard
180+
chainId === chainToChainId('Acala')
176181
? `https://blockscout.mandala.aca-staging.network/tx/${tx}`
177-
: chainId === toChainId('Klaytn')
182+
: chainId === chainToChainId('Klaytn')
178183
? `https://baobab.klaytnscope.com/tx/${tx}`
179-
: chainId === toChainId('Celo')
184+
: chainId === chainToChainId('Celo')
180185
? `https://alfajores.celoscan.io/tx/${tx}`
181-
: // chainId === toChainId('Near') <-- not supported on testnet dashboard
182-
chainId === toChainId('Moonbeam')
186+
: // chainId === chainToChainId('Near') <-- not supported on testnet dashboard
187+
chainId === chainToChainId('Moonbeam')
183188
? `https://moonbase.moonscan.io/tx/${tx}`
184-
: // chainId === toChainId('Terra2') <-- not supported on testnet dashboard
185-
// chainId === toChainId('Injective') <-- not supported on testnet dashboard
186-
chainId === toChainId('Sui')
189+
: // chainId === chainToChainId('Terra2') <-- not supported on testnet dashboard
190+
// chainId === chainToChainId('Injective') <-- not supported on testnet dashboard
191+
chainId === chainToChainId('Sui')
187192
? `https://suiexplorer.com/txblock/${tx}?network=testnet`
188-
: chainId === toChainId('Aptos')
193+
: chainId === chainToChainId('Aptos')
189194
? `https://explorer.aptoslabs.com/txn/${tx}?network=testnet`
190-
: chainId === toChainId('Arbitrum')
195+
: chainId === chainToChainId('Arbitrum')
191196
? `https://sepolia.arbiscan.io/tx/${tx}`
192-
: chainId === toChainId('Optimism')
197+
: chainId === chainToChainId('Optimism')
193198
? `https://sepolia-optimism.etherscan.io/tx/${tx}`
194-
: chainId === toChainId('Xpla')
199+
: chainId === chainToChainId('Xpla')
195200
? `https://explorer.xpla.io/testnet/tx/${tx}`
196-
: chainId === toChainId('Base')
201+
: chainId === chainToChainId('Base')
197202
? `https://goerli.basescan.org/tx/${tx}`
198-
: chainId === toChainId('Sei')
203+
: chainId === chainToChainId('Sei')
199204
? `https://www.seiscan.app/atlantic-2/txs/${tx}`
200-
: // chainId === toChainId('Wormscan') <-- not supported on testnet dashboard
205+
: // chainId === chainToChainId('Wormscan') <-- not supported on testnet dashboard
201206
'';
202207

203208
export const explorerVaa = (network: string, key: string) =>

0 commit comments

Comments
 (0)