@@ -34,6 +34,7 @@ export type ConstituentMapConfig = {
3434 lpPoolId ?: number ;
3535 // potentially use these to filter Constituent accounts
3636 additionalFilters ?: MemcmpFilter [ ] ;
37+ decoder ?: 'base64' | 'base64+zstd' ;
3738} ;
3839
3940export interface ConstituentMapInterface {
@@ -65,13 +66,15 @@ export class ConstituentMap implements ConstituentMapInterface {
6566 private spotMarketIndexToKeyMap = new Map < number , string > ( ) ;
6667
6768 private lpPoolId : number ;
69+ private decoder : 'base64' | 'base64+zstd' ;
6870
6971 constructor ( config : ConstituentMapConfig ) {
7072 this . driftClient = config . driftClient ;
7173 this . additionalFilters = config . additionalFilters ;
7274 this . commitment = config . subscriptionConfig . commitment ;
7375 this . connection = config . connection || this . driftClient . connection ;
7476 this . lpPoolId = config . lpPoolId ?? 0 ;
77+ this . decoder = config . decoder ?? 'base64+zstd' ;
7578
7679 if ( config . subscriptionConfig . type === 'polling' ) {
7780 this . constituentAccountSubscriber =
@@ -129,7 +132,7 @@ export class ConstituentMap implements ConstituentMapInterface {
129132 {
130133 commitment : this . commitment ,
131134 filters : this . getFilters ( ) ,
132- encoding : 'base64+zstd' ,
135+ encoding : this . decoder ,
133136 withContext : true ,
134137 } ,
135138 ] ;
@@ -146,15 +149,22 @@ export class ConstituentMap implements ConstituentMapInterface {
146149
147150 const promises = rpcResponseAndContext . value . map (
148151 async ( programAccount ) => {
149- const compressedUserData = Buffer . from (
150- programAccount . account . data [ 0 ] ,
151- 'base64'
152- ) ;
153- const decoder = new ZSTDDecoder ( ) ;
154- await decoder . init ( ) ;
155- const buffer = Buffer . from (
156- decoder . decode ( compressedUserData , MAX_CONSTITUENT_SIZE_BYTES )
157- ) ;
152+ let buffer : Buffer ;
153+
154+ if ( this . decoder === 'base64+zstd' ) {
155+ const compressedUserData = Buffer . from (
156+ programAccount . account . data [ 0 ] ,
157+ 'base64'
158+ ) ;
159+ const decoder = new ZSTDDecoder ( ) ;
160+ await decoder . init ( ) ;
161+ buffer = Buffer . from (
162+ decoder . decode ( compressedUserData , MAX_CONSTITUENT_SIZE_BYTES )
163+ ) ;
164+ } else {
165+ buffer = Buffer . from ( programAccount . account . data [ 0 ] , 'base64' ) ;
166+ }
167+
158168 const key = programAccount . pubkey . toString ( ) ;
159169 const currAccountWithSlot = this . getWithSlot ( key ) ;
160170
0 commit comments