@@ -326,26 +326,22 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
326326 }
327327
328328 override async subscribeToOracles ( ) : Promise < boolean > {
329- // Build list of unique oracle pubkeys and a lookup for sources
330- const uniqueOraclePubkeys = new Map < string , OracleInfo > ( ) ;
329+ const pubkeyToSources = new Map < string , Set < OracleInfo [ 'source' ] > > ( ) ;
331330 for ( const info of this . oracleInfos ) {
332- const id = getOracleId ( info . publicKey , info . source ) ;
333- if (
334- ! uniqueOraclePubkeys . has ( id ) &&
335- ! info . publicKey . equals ( ( PublicKey as any ) . default )
336- ) {
337- uniqueOraclePubkeys . set ( id , info ) ;
331+ if ( info . publicKey . equals ( ( PublicKey as any ) . default ) ) {
332+ continue ;
333+ }
334+ const key = info . publicKey . toBase58 ( ) ;
335+ let sources = pubkeyToSources . get ( key ) ;
336+ if ( ! sources ) {
337+ sources = new Set < OracleInfo [ 'source' ] > ( ) ;
338+ pubkeyToSources . set ( key , sources ) ;
338339 }
340+ sources . add ( info . source ) ;
339341 }
340342
341- const oraclePubkeys = Array . from ( uniqueOraclePubkeys . values ( ) ) . map (
342- ( i ) => i . publicKey
343- ) ;
344- const pubkeyToSource = new Map < string , OracleInfo [ 'source' ] > (
345- Array . from ( uniqueOraclePubkeys . values ( ) ) . map ( ( i ) => [
346- i . publicKey . toBase58 ( ) ,
347- i . source ,
348- ] )
343+ const oraclePubkeys = Array . from ( pubkeyToSources . keys ( ) ) . map (
344+ ( k ) => new PublicKey ( k )
349345 ) ;
350346
351347 this . oracleMultiSubscriber =
@@ -357,9 +353,13 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
357353 if ( ! pubkey ) {
358354 throw new Error ( 'Oracle pubkey missing in decode' ) ;
359355 }
360- const source = pubkeyToSource . get ( pubkey ) ;
356+ const sources = pubkeyToSources . get ( pubkey ) ;
357+ if ( ! sources || sources . size === 0 ) {
358+ throw new Error ( 'Oracle sources missing for pubkey in decode' ) ;
359+ }
360+ const primarySource = sources . values ( ) . next ( ) . value ;
361361 const client = this . oracleClientCache . get (
362- source ,
362+ primarySource ,
363363 this . program . provider . connection ,
364364 this . program
365365 ) ;
@@ -389,8 +389,17 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
389389 await this . oracleMultiSubscriber . subscribe (
390390 oraclePubkeys ,
391391 ( accountId , data ) => {
392- const source = pubkeyToSource . get ( accountId . toBase58 ( ) ) ;
393- this . eventEmitter . emit ( 'oraclePriceUpdate' , accountId , source , data ) ;
392+ const sources = pubkeyToSources . get ( accountId . toBase58 ( ) ) ;
393+ if ( sources ) {
394+ for ( const source of sources . values ( ) ) {
395+ this . eventEmitter . emit (
396+ 'oraclePriceUpdate' ,
397+ accountId ,
398+ source ,
399+ data
400+ ) ;
401+ }
402+ }
394403 this . eventEmitter . emit ( 'update' ) ;
395404 }
396405 ) ;
0 commit comments