11import type { Address } from "viem" ;
22
3- import { iMarketCompressorAbi } from "../abi" ;
4- import type { MarketData } from "../base" ;
3+ import { iMarketCompressorAbi , iPeripheryCompressorAbi } from "../abi" ;
4+ import type { MarketData , ZapperData } from "../base" ;
55import { SDKConstruct } from "../base" ;
6- import { ADDRESS_0X0 , AP_MARKET_COMPRESSOR } from "../constants" ;
6+ import {
7+ ADDRESS_0X0 ,
8+ AP_MARKET_COMPRESSOR ,
9+ AP_PERIPHERY_COMPRESSOR ,
10+ } from "../constants" ;
711import type { GearboxSDK } from "../GearboxSDK" ;
8- import type { ILogger , MarketStateHuman , RawTx , TVL } from "../types" ;
12+ import type {
13+ ILogger ,
14+ MarketStateHuman ,
15+ RawTx ,
16+ TVL ,
17+ ZapperStateHuman ,
18+ } from "../types" ;
919import { AddressMap , childLogger } from "../utils" ;
1020import { simulateMulticall } from "../utils/viem" ;
1121import type { CreditSuite } from "./CreditSuite" ;
@@ -20,6 +30,7 @@ export class MarketRegister extends SDKConstruct {
2030 * Mapping pool.address -> MarketSuite
2131 */
2232 #markets = new AddressMap < MarketSuite > ( ) ;
33+ #zappers: ZapperData [ ] = [ ] ;
2334
2435 constructor ( sdk : GearboxSDK , markets ?: MarketData [ ] ) {
2536 super ( sdk ) ;
@@ -45,6 +56,29 @@ export class MarketRegister extends SDKConstruct {
4556 await this . #loadMarkets( marketConfigurators , [ ] , ignoreUpdateablePrices ) ;
4657 }
4758
59+ public async loadZappers ( ) : Promise < void > {
60+ const pcAddr = this . sdk . addressProvider . getAddress (
61+ AP_PERIPHERY_COMPRESSOR ,
62+ 3_10 ,
63+ ) ;
64+ this . #logger?. debug ( `loading zappers with periphery compressor ${ pcAddr } ` ) ;
65+ const resp = await this . provider . publicClient . multicall ( {
66+ contracts : this . markets . map ( m => ( {
67+ abi : iPeripheryCompressorAbi ,
68+ address : pcAddr ,
69+ functionName : "getZappers" ,
70+ args : [ m . configurator , m . pool . pool . address ] ,
71+ } ) ) ,
72+ allowFailure : false ,
73+ } ) ;
74+ this . #zappers = resp . flat ( ) as any as ZapperData [ ] ;
75+ const zappersTokens = this . #zappers. flatMap ( z => [ z . tokenIn , z . tokenOut ] ) ;
76+ for ( const t of zappersTokens ) {
77+ this . sdk . tokensMeta . upsert ( t . addr , t ) ;
78+ this . sdk . provider . addressLabels . set ( t . addr as Address , t . symbol ) ;
79+ }
80+ }
81+
4882 public async syncState ( ) : Promise < void > {
4983 const pools = this . markets
5084 . filter ( m => m . dirty )
@@ -144,8 +178,20 @@ export class MarketRegister extends SDKConstruct {
144178 return this . markets . map ( market => market . state ) ;
145179 }
146180
147- public stateHuman ( raw = true ) : MarketStateHuman [ ] {
148- return this . markets . map ( market => market . stateHuman ( raw ) ) ;
181+ public stateHuman ( raw = true ) : {
182+ markets : MarketStateHuman [ ] ;
183+ zappers : ZapperStateHuman [ ] ;
184+ } {
185+ return {
186+ markets : this . markets . map ( market => market . stateHuman ( raw ) ) ,
187+ zappers : this . zappers . map ( z => ( {
188+ address : z . baseParams . addr ,
189+ contractType : z . baseParams . contractType ,
190+ version : Number ( z . baseParams . version ) ,
191+ tokenIn : this . labelAddress ( z . tokenIn . addr ) ,
192+ tokenOut : this . labelAddress ( z . tokenOut . addr ) ,
193+ } ) ) ,
194+ } ;
149195 }
150196
151197 public get pools ( ) : PoolSuite [ ] {
@@ -213,6 +259,10 @@ export class MarketRegister extends SDKConstruct {
213259 return this . #markets;
214260 }
215261
262+ public get zappers ( ) : ZapperData [ ] {
263+ return this . #zappers;
264+ }
265+
216266 public get markets ( ) : MarketSuite [ ] {
217267 return this . #markets. values ( ) ;
218268 }
0 commit comments