@@ -15,6 +15,7 @@ import (
1515 "github.com/Gearbox-protocol/sdk-go/artifacts/dataCompressor/mainnet"
1616 "github.com/Gearbox-protocol/sdk-go/artifacts/dataCompressorv3"
1717 dcv3 "github.com/Gearbox-protocol/sdk-go/artifacts/dataCompressorv3"
18+ "github.com/Gearbox-protocol/sdk-go/artifacts/globalAccountCompressor"
1819 "github.com/Gearbox-protocol/sdk-go/artifacts/multicall"
1920 "github.com/Gearbox-protocol/sdk-go/artifacts/poolCompressor"
2021 "github.com/Gearbox-protocol/sdk-go/core"
@@ -158,8 +159,26 @@ func (dcw *DataCompressorWrapper) addDataCompressorv300(version core.VersionType
158159 })
159160}
160161
162+ var ContractNameToCompressortype = map [string ]CompressorType {
163+ // "POOL_COMPRESSOR": dc_wrapper.POOL_COMPRESSOR,
164+ "MARKET_COMPRESSOR" : MARKET_COMPRESSOR ,
165+ "CREDIT_ACCOUNT_COMPRESSOR" : CREDIT_ACCOUNT_COMPRESSOR ,
166+ "POOL_COMPRESSOR" : POOL_COMPRESSOR ,
167+ "GLOBAL::ACCOUNT_COMPRESSOR" : GLOBAL_ACCOUNT_COMPRESSOR ,
168+ "GLOBAL::MARKET_COMPRESSOR" : GLOBAL_MARKET_COMPRESSOR ,
169+ }
170+
171+ func isCType (c CompressorType ) bool {
172+ for _ , v := range ContractNameToCompressortype {
173+ if c == v {
174+ return true
175+ }
176+ }
177+ return false
178+ }
179+
161180func (dcw * DataCompressorWrapper ) AddCompressorType (addr common.Address , cType CompressorType , discoveredAt int64 ) {
162- if ! utils . Contains ([] CompressorType { MARKET_COMPRESSOR , CREDIT_ACCOUNT_COMPRESSOR , POOL_COMPRESSOR }, cType ) {
181+ if ! isCType ( cType ) {
163182 log .Fatal ("ctype is wrong, " , cType )
164183 }
165184 if len (dcw .compressorByBlock [cType ]) > 0 {
@@ -224,34 +243,38 @@ const (
224243 MARKET_COMPRESSOR CompressorType = "MARKET"
225244 POOL_COMPRESSOR CompressorType = "POOL"
226245 CREDIT_ACCOUNT_COMPRESSOR CompressorType = "ACCOUNT"
246+ GLOBAL_MARKET_COMPRESSOR CompressorType = "GLOBALMARKET"
247+ GLOBAL_ACCOUNT_COMPRESSOR CompressorType = "GLOBALACCOUNT"
227248)
228249
229250// checks in versionToAddress for v300 and then checks in addrByBlock for v1,v2
230- func (dcw * DataCompressorWrapper ) GetKeyAndAddress (version core.VersionType , blockNum int64 , cType CompressorType ) (string , common.Address ) {
251+ func (dcw * DataCompressorWrapper ) GetKeyAndAddress (version core.VersionType , blockNum int64 , cTypes [] CompressorType ) (string , common.Address , CompressorType ) {
231252 if blockNum == 0 {
232253 log .Fatal ("blockNum can't be zero" )
233254 }
234255 // v300
235256 if version .MoreThanEq (core .NewVersion (300 )) {
236257 // v310
237- for i := len (dcw .compressorByBlock [cType ]) - 1 ; i >= 0 ; i -- {
238- compressorDetails := dcw.compressorByBlock [cType ][i ]
239- if compressorDetails .block <= blockNum {
240- return DCV310 , compressorDetails .address
258+ for _ , cType := range cTypes {
259+ for i := len (dcw .compressorByBlock [cType ]) - 1 ; i >= 0 ; i -- {
260+ compressorDetails := dcw.compressorByBlock [cType ][i ]
261+ if compressorDetails .block <= blockNum {
262+ return DCV310 , compressorDetails .address , cType
263+ }
241264 }
242265 }
243266 // v300
244267 arr := dcw .versionToAddress [version ]
245268 for i := len (arr ) - 1 ; i >= 0 ; i -- {
246269 if arr [i ].block <= blockNum {
247- return DCV3 , arr [i ].address
270+ return DCV3 , arr [i ].address , ""
248271 }
249272 }
250- return NODC , core .NULL_ADDR
273+ return NODC , core .NULL_ADDR , ""
251274 }
252275 // for v2, v1
253276 key , discoveredAt := dcw .getDataCompressorIndex (blockNum )
254- return key , dcw .getDCAddr (discoveredAt )
277+ return key , dcw .getDCAddr (discoveredAt ), ""
255278}
256279
257280// checks in versionToAddress for v300 and then checks in addrByBlock for v1,v2
@@ -266,7 +289,7 @@ func (dcw *DataCompressorWrapper) GetLatestv3DC() (common.Address, bool) {
266289}
267290
268291func (dcw * DataCompressorWrapper ) Retry (blockNum int64 , account common.Address , v3Pods []dataCompressorv3.PriceOnDemand , v3PodCalls []multicall.Multicall2Call ) (dc.CreditAccountCallData , error ) {
269- key , dcAddr := dcw .GetKeyAndAddress (core .NewVersion (300 ), blockNum , CREDIT_ACCOUNT_COMPRESSOR )
292+ key , dcAddr , compressorType := dcw .GetKeyAndAddress (core .NewVersion (300 ), blockNum , [] CompressorType { CREDIT_ACCOUNT_COMPRESSOR , GLOBAL_ACCOUNT_COMPRESSOR } )
270293 opts := & bind.CallOpts {BlockNumber : big .NewInt (blockNum )}
271294 switch key {
272295 case NODC :
@@ -281,7 +304,16 @@ func (dcw *DataCompressorWrapper) Retry(blockNum int64, account common.Address,
281304 }
282305 return dc .GetAccountDataFromDCCall (dcw .client , core .NULL_ADDR , blockNum , data )
283306 case DCV310 :
284- callData , err := core .GetAbi ("CreditAccountCompressor" ).Pack ("getCreditAccountData" , account )
307+ abiType := func () string {
308+ if compressorType == CREDIT_ACCOUNT_COMPRESSOR {
309+ return "CreditAccountCompressor"
310+ } else if compressorType == GLOBAL_ACCOUNT_COMPRESSOR {
311+ return "GlobalAccountCompressor"
312+ }
313+ log .Fatal ("compressor type not found" )
314+ return ""
315+ }()
316+ callData , err := core .GetAbi (abiType ).Pack ("getCreditAccountData" , account )
285317 log .CheckFatal (err )
286318 v3PodCalls = append (v3PodCalls , multicall.Multicall2Call {
287319 Target : dcAddr ,
@@ -293,11 +325,18 @@ func (dcw *DataCompressorWrapper) Retry(blockNum int64, account common.Address,
293325 log .Warn ("after retry, getCreditAccoutn data is still not successful" , blockNum , account )
294326 return dc.CreditAccountCallData {}, err
295327 }
296- out , err := core .GetAbi ("CreditAccountCompressor" ).Unpack ("getCreditAccountData" , data .ReturnData )
328+ out , err := core .GetAbi (abiType ).Unpack ("getCreditAccountData" , data .ReturnData )
297329 if err != nil {
298330 return dc.CreditAccountCallData {}, err
299331 }
300- accountData := * abi .ConvertType (out [0 ], new (creditAccountCompressor.CreditAccountData )).(* creditAccountCompressor.CreditAccountData )
332+ var accountData creditAccountCompressor.CreditAccountData
333+ switch compressorType {
334+ case CREDIT_ACCOUNT_COMPRESSOR :
335+ accountData = * abi .ConvertType (out [0 ], new (creditAccountCompressor.CreditAccountData )).(* creditAccountCompressor.CreditAccountData )
336+ case GLOBAL_ACCOUNT_COMPRESSOR :
337+ x := abi .ConvertType (out [0 ], new (globalAccountCompressor.CreditAccountData )).(* globalAccountCompressor.CreditAccountData )
338+ accountData = dc .Convert (x )
339+ }
301340 log .Info (utils .ToJson (accountData ))
302341 if ! accountData .Success {
303342 log .Warn ("Not success v3" , blockNum , account )
@@ -315,16 +354,25 @@ func (dcw *DataCompressorWrapper) GetCreditAccountData(version core.VersionType,
315354 resultFn func ([]byte ) (dc.CreditAccountCallData , error ),
316355 errReturn error ) {
317356 //
318- key , dcAddr := dcw .GetKeyAndAddress (version , blockNum , CREDIT_ACCOUNT_COMPRESSOR )
357+ key , dcAddr , compressorType := dcw .GetKeyAndAddress (version , blockNum , [] CompressorType { CREDIT_ACCOUNT_COMPRESSOR , GLOBAL_ACCOUNT_COMPRESSOR } )
319358 switch key {
320359 case NODC :
321360 errReturn = NO_DC_FOUND_ERR
322361 case DCV310 :
323- data , err := core .GetAbi ("CreditAccountCompressor" ).Pack ("getCreditAccountData" , account )
324- call , errReturn = multicall.Multicall2Call {
325- Target : dcAddr ,
326- CallData : data ,
327- }, err
362+ switch compressorType {
363+ case CREDIT_ACCOUNT_COMPRESSOR :
364+ data , err := core .GetAbi ("CreditAccountCompressor" ).Pack ("getCreditAccountData" , account )
365+ call , errReturn = multicall.Multicall2Call {
366+ Target : dcAddr ,
367+ CallData : data ,
368+ }, err
369+ case GLOBAL_ACCOUNT_COMPRESSOR :
370+ data , err := core .GetAbi ("GlobalAccountCompressor" ).Pack ("getCreditAccountData" , account )
371+ call , errReturn = multicall.Multicall2Call {
372+ Target : dcAddr ,
373+ CallData : data ,
374+ }, err
375+ }
328376 case DCV3 :
329377 data , err := core .GetAbi ("DataCompressorv3" ).Pack ("getCreditAccountData" , account , []dcv3.PriceOnDemand {})
330378 call , errReturn = multicall.Multicall2Call {
@@ -357,7 +405,14 @@ func (dcw *DataCompressorWrapper) GetCreditAccountData(version core.VersionType,
357405 case NODC :
358406 log .Fatal ("No data compressor found for credit account data" )
359407 case DCV310 :
360- out , err := core .GetAbi ("CreditAccountCompressor" ).Unpack ("getCreditAccountData" , bytes )
408+ var out []interface {}
409+ var err error
410+ switch compressorType {
411+ case CREDIT_ACCOUNT_COMPRESSOR :
412+ out , err = core .GetAbi ("CreditAccountCompressor" ).Unpack ("getCreditAccountData" , bytes )
413+ case GLOBAL_ACCOUNT_COMPRESSOR :
414+ out , err = core .GetAbi ("GlobalAccountCompressor" ).Unpack ("getCreditAccountData" , bytes )
415+ }
361416 if err != nil {
362417 return dc.CreditAccountCallData {}, err
363418 }
@@ -399,7 +454,7 @@ func (dcw *DataCompressorWrapper) GetCreditManagerData(version core.VersionType,
399454 resultFn func ([]byte ) (dc.CMCallData , error ),
400455 errReturn error ) {
401456 //
402- key , dcAddr := dcw .GetKeyAndAddress (version , blockNum , MARKET_COMPRESSOR )
457+ key , dcAddr , _ := dcw .GetKeyAndAddress (version , blockNum , [] CompressorType { MARKET_COMPRESSOR , GLOBAL_MARKET_COMPRESSOR } )
403458 switch key {
404459 case NODC :
405460 errReturn = NO_DC_FOUND_ERR
@@ -536,7 +591,7 @@ func (dcw *DataCompressorWrapper) getZapperInfov3(blockNum int64, poolAddrs ...c
536591}
537592
538593func (dcw * DataCompressorWrapper ) GetZapperInfo (blockNum int64 , poolAddrs ... common.Address ) (ans []PoolZapperInfo ) {
539- key , _ := dcw .GetKeyAndAddress (core .NewVersion (300 ), blockNum , MARKET_COMPRESSOR )
594+ key , _ , _ := dcw .GetKeyAndAddress (core .NewVersion (300 ), blockNum , [] CompressorType { MARKET_COMPRESSOR } )
540595 switch key {
541596 case DCV310 :
542597 data , err := dcw .getZapperInfov3 (blockNum , poolAddrs ... )
@@ -588,16 +643,25 @@ func (dcw *DataCompressorWrapper) GetPoolData(version core.VersionType, blockNum
588643 resultFn func ([]byte ) (dc.PoolCallData , error ),
589644 errReturn error ) {
590645 //
591- key , dcAddr := dcw .GetKeyAndAddress (version , blockNum , POOL_COMPRESSOR )
646+ key , dcAddr , compressorType := dcw .GetKeyAndAddress (version , blockNum , [] CompressorType { POOL_COMPRESSOR , GLOBAL_MARKET_COMPRESSOR } )
592647 switch key {
593648 case NODC :
594649 errReturn = NO_DC_FOUND_ERR
595650 case DCV310 :
596- data , err := core .GetAbi ("PoolCompressor" ).Pack ("getPoolState" , _pool )
597- call , errReturn = multicall.Multicall2Call {
598- Target : dcAddr ,
599- CallData : data ,
600- }, err
651+ switch compressorType {
652+ case POOL_COMPRESSOR :
653+ data , err := core .GetAbi ("PoolCompressor" ).Pack ("getPoolState" , _pool )
654+ call , errReturn = multicall.Multicall2Call {
655+ Target : dcAddr ,
656+ CallData : data ,
657+ }, err
658+ case GLOBAL_MARKET_COMPRESSOR :
659+ data , err := core .GetAbi ("GlobalMarketCompressor" ).Pack ("getPoolState" , _pool )
660+ call , errReturn = multicall.Multicall2Call {
661+ Target : dcAddr ,
662+ CallData : data ,
663+ }, err
664+ }
601665 case DCV3 :
602666 data , err := core .GetAbi ("DataCompressorv3" ).Pack ("getPoolData" , _pool )
603667 call , errReturn = multicall.Multicall2Call {
@@ -631,7 +695,14 @@ func (dcw *DataCompressorWrapper) GetPoolData(version core.VersionType, blockNum
631695 case NODC :
632696 log .Fatal ("No data compressor found for pool data" )
633697 case DCV310 :
634- out , err := core .GetAbi ("PoolCompressor" ).Unpack ("getPoolState" , bytes )
698+ var out []interface {}
699+ var err error
700+ switch compressorType {
701+ case POOL_COMPRESSOR :
702+ out , err = core .GetAbi ("PoolCompressor" ).Unpack ("getPoolState" , bytes )
703+ case GLOBAL_MARKET_COMPRESSOR :
704+ out , err = core .GetAbi ("GlobalMarketCompressor" ).Unpack ("getPoolState" , bytes )
705+ }
635706 if err != nil {
636707 return dc.PoolCallData {}, err
637708 }
0 commit comments