@@ -39,6 +39,11 @@ export interface ConstituentMapInterface {
3939 unsubscribe ( ) : Promise < void > ;
4040 has ( key : string ) : boolean ;
4141 get ( key : string ) : ConstituentAccount | undefined ;
42+ getFromSpotMarketIndex (
43+ spotMarketIndex : number ) : ConstituentAccount | undefined ;
44+ getFromConstituentIndex (
45+ constituentIndex : number ) : ConstituentAccount | undefined ;
46+
4247 getWithSlot ( key : string ) : DataAndSlot < ConstituentAccount > | undefined ;
4348 mustGet ( key : string ) : Promise < ConstituentAccount > ;
4449 mustGetWithSlot ( key : string ) : Promise < DataAndSlot < ConstituentAccount > > ;
@@ -52,6 +57,9 @@ export class ConstituentMap implements ConstituentMapInterface {
5257 private commitment ?: Commitment ;
5358 private connection ?: Connection ;
5459
60+ private constituentIndexToKeyMap = new Map < number , string > ( ) ;
61+ private spotMarketIndexToKeyMap = new Map < number , string > ( ) ;
62+
5563 constructor ( config : ConstituentMapConfig ) {
5664 this . driftClient = config . driftClient ;
5765 this . additionalFilters = config . additionalFilters ;
@@ -172,6 +180,16 @@ export class ConstituentMap implements ConstituentMapInterface {
172180 return this . constituentMap . get ( key ) ?. data ;
173181 }
174182
183+ public getFromConstituentIndex ( constituentIndex : number ) : ConstituentAccount | undefined {
184+ const key = this . constituentIndexToKeyMap . get ( constituentIndex ) ;
185+ return key ? this . get ( key ) : undefined ;
186+ }
187+
188+ public getFromSpotMarketIndex ( spotMarketIndex : number ) : ConstituentAccount | undefined {
189+ const key = this . spotMarketIndexToKeyMap . get ( spotMarketIndex ) ;
190+ return key ? this . get ( key ) : undefined ;
191+ }
192+
175193 public getWithSlot ( key : string ) : DataAndSlot < ConstituentAccount > | undefined {
176194 return this . constituentMap . get ( key ) ;
177195 }
@@ -245,5 +263,13 @@ export class ConstituentMap implements ConstituentMapInterface {
245263 slot,
246264 } ) ;
247265 }
266+ this . constituentIndexToKeyMap . set (
267+ constituentAccount . constituentIndex ,
268+ key
269+ ) ;
270+ this . spotMarketIndexToKeyMap . set (
271+ constituentAccount . spotMarketIndex ,
272+ key
273+ ) ;
248274 }
249275}
0 commit comments