1
1
import { CHAIN_ID_TO_NAME , ChainId , ChainName } from '@certusone/wormhole-sdk' ;
2
2
import { MissingVaasByChain , commonGetMissingVaas } from './getMissingVaas' ;
3
+ import { GovernedVAAMap , getGovernedVaas } from './getGovernedVaas' ;
3
4
import { assertEnvironmentVariable , formatAndSendToSlack , isVAASigned } from './utils' ;
4
5
import { ObservedMessage , ReobserveInfo , SlackInfo } from './types' ;
5
6
import {
@@ -10,35 +11,6 @@ import {
10
11
} from '@wormhole-foundation/wormhole-monitor-common' ;
11
12
import { Firestore } from 'firebase-admin/firestore' ;
12
13
13
- interface EnqueuedVAAResponse {
14
- sequence : string ;
15
- releaseTime : number ;
16
- notionalValue : string ;
17
- txHash : string ;
18
- }
19
-
20
- interface Emitter {
21
- emitterAddress : string ;
22
- enqueuedVaas : EnqueuedVAAResponse [ ] ;
23
- totalEnqueuedVaas : string ;
24
- }
25
-
26
- interface ChainStatus {
27
- availableNotional : string ;
28
- chainId : number ;
29
- emitters : Emitter [ ] ;
30
- }
31
-
32
- interface GovernedVAA {
33
- chainId : number ;
34
- emitterAddress : string ;
35
- sequence : string ;
36
- txHash : string ;
37
- }
38
-
39
- // The key is the vaaKey
40
- type GovernedVAAMap = Map < string , GovernedVAA > ;
41
-
42
14
const network : Environment = getEnvironment ( ) ;
43
15
44
16
export async function alarmMissingVaas ( req : any , res : any ) {
@@ -153,48 +125,6 @@ export async function alarmMissingVaas(req: any, res: any) {
153
125
return ;
154
126
}
155
127
156
- // This function gets all the enqueued VAAs from he governorStatus collection.
157
- async function getGovernedVaas ( ) : Promise < GovernedVAAMap > {
158
- const vaas : GovernedVAAMap = new Map < string , GovernedVAA > ( ) ;
159
- // Walk all the guardians and retrieve the enqueued VAAs
160
- const firestore = new Firestore ( ) ;
161
- const collection = firestore . collection (
162
- assertEnvironmentVariable ( 'FIRESTORE_GOVERNOR_STATUS_COLLECTION' )
163
- ) ;
164
- const snapshot = await collection . get ( ) ;
165
- for ( const doc of snapshot . docs ) {
166
- const data = doc . data ( ) ;
167
- if ( data ) {
168
- // data should be a ChainStatus[]
169
- const chains : ChainStatus [ ] = data . chains ;
170
- chains . forEach ( ( chain ) => {
171
- // chain should be a ChainStatus
172
- const emitters : Emitter [ ] = chain . emitters ;
173
- emitters . forEach ( ( emitter ) => {
174
- // Filter 0x off the front of the emitter address
175
- if ( emitter . emitterAddress . startsWith ( '0x' ) ) {
176
- emitter . emitterAddress = emitter . emitterAddress . slice ( 2 ) ;
177
- }
178
- // emitter should be an Emitter
179
- const enqueuedVaas : EnqueuedVAAResponse [ ] = emitter . enqueuedVaas ;
180
- enqueuedVaas . forEach ( ( vaa ) => {
181
- // vaa should be an EnqueuedVAAResponse
182
- const governedVAA : GovernedVAA = {
183
- chainId : chain . chainId ,
184
- emitterAddress : emitter . emitterAddress ,
185
- sequence : vaa . sequence ,
186
- txHash : vaa . txHash ,
187
- } ;
188
- const key = `${ chain . chainId } /${ emitter . emitterAddress } /${ vaa . sequence } ` ;
189
- vaas . set ( key , governedVAA ) ;
190
- } ) ;
191
- } ) ;
192
- } ) ;
193
- }
194
- }
195
- return vaas ;
196
- }
197
-
198
128
// This function gets all the VAAs in the firestore table,
199
129
// checks the timestamp (keeping any that are less than 2 hours old),
200
130
// and returns a map of those VAAs.
0 commit comments