@@ -7,17 +7,19 @@ import type {
77
88import { botListV3Abi } from "../abi" ;
99import { BaseContract } from "../base" ;
10- import { botPermissionsToString } from "../constants" ;
10+ import { ADDRESS_PROVIDER_BLOCK , botPermissionsToString } from "../constants" ;
1111import type { GearboxSDK } from "../GearboxSDK" ;
1212import type { BotListStateHuman } from "../types" ;
1313
1414type abi = typeof botListV3Abi ;
1515
1616export class BotListContract extends BaseContract < abi > {
17- approvedCreditManagers : Set < Address > = new Set ( ) ;
17+ #approvedCreditManagers?: Set < Address > ;
18+ #currentBlock: bigint ;
1819
1920 constructor ( sdk : GearboxSDK , address : Address ) {
2021 super ( sdk , { addr : address , name : "BotListV3" , abi : botListV3Abi } ) ;
22+ this . #currentBlock = ADDRESS_PROVIDER_BLOCK [ sdk . provider . networkType ] ;
2123 }
2224
2325 public parseFunctionParams (
@@ -41,15 +43,15 @@ export class BotListContract extends BaseContract<abi> {
4143 }
4244 }
4345
44- public async fetchState ( toBlock : bigint ) : Promise < void > {
46+ public async syncState ( toBlock : bigint ) : Promise < void > {
4547 const logs = await this . provider . publicClient . getContractEvents ( {
4648 address : this . address ,
4749 abi : this . abi ,
48- fromBlock : 0n ,
50+ fromBlock : this . #currentBlock ,
4951 toBlock,
5052 } ) ;
51-
5253 logs . forEach ( e => this . processLog ( e ) ) ;
54+ this . #currentBlock = toBlock ;
5355 }
5456
5557 public override processLog (
@@ -85,6 +87,15 @@ export class BotListContract extends BaseContract<abi> {
8587 }
8688 }
8789
90+ public get approvedCreditManagers ( ) : Set < Address > {
91+ if ( ! this . #approvedCreditManagers) {
92+ throw new Error (
93+ "BotListContract state needs to be synced to load approvedCreditManagers" ,
94+ ) ;
95+ }
96+ return this . #approvedCreditManagers;
97+ }
98+
8899 public override stateHuman ( raw = true ) : BotListStateHuman {
89100 return super . stateHuman ( raw ) ;
90101 }
0 commit comments