@@ -39,6 +39,7 @@ import type { ILogger, IPriceUpdateTx, MultiCall } from "../types/index.js";
3939import { AddressMap , childLogger } from "../utils/index.js" ;
4040import { simulateWithPriceUpdates } from "../utils/viem/index.js" ;
4141import type {
42+ AccountToCheck ,
4243 AddCollateralProps ,
4344 ChangeDeptProps ,
4445 ClaimDelayedProps ,
@@ -280,18 +281,22 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
280281
281282 /**
282283 * Method to get all connected bots for credit account
283- * @param {Array<{ creditAccount: Address; creditManager: Address } > } accountsToCheck - list of credit accounts
284+ * @param {Array<AccountToCheck > } accountsToCheck - list of credit accounts
284285 and their credit managers to check connected bots on
285286 * @returns call result of getConnectedBots for each credit account
286287 */
287288 public async getConnectedBots (
288- accountsToCheck : Array < { creditAccount : Address ; creditManager : Address } > ,
289+ accountsToCheck : Array < AccountToCheck > ,
289290 legacyMigrationBot : Address | undefined ,
291+ additionalBots : Array < Address > ,
290292 ) : Promise < {
291293 legacy : GetConnectedBotsResult ;
292294 legacyMigration : GetConnectedMigrationBotsResult ;
295+ additionalBots : Array <
296+ Omit < NonNullable < GetConnectedMigrationBotsResult > , "botAddress" >
297+ > ;
293298 } > {
294- const [ resp , migration ] = await Promise . all ( [
299+ const [ resp , migration , additional ] = await Promise . all ( [
295300 this . client . multicall ( {
296301 contracts : accountsToCheck . map ( o => {
297302 const pool = this . sdk . marketRegister . findByCreditManager (
@@ -308,15 +313,58 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
308313 allowFailure : true ,
309314 } ) ,
310315 this . getActiveMigrationBots ( accountsToCheck , legacyMigrationBot ) ,
316+ this . getActiveBots ( accountsToCheck , additionalBots ) ,
311317 ] ) ;
312318
313- return { legacy : resp , legacyMigration : migration } ;
319+ return {
320+ legacy : resp ,
321+ additionalBots : additional ,
322+ legacyMigration : migration ,
323+ } ;
324+ }
325+ private async getActiveBots (
326+ accountsToCheck : Array < AccountToCheck > ,
327+ bots : Array < Address > ,
328+ ) {
329+ const result = await this . client . multicall ( {
330+ contracts : accountsToCheck . flatMap ( ca => {
331+ const cm = this . sdk . marketRegister . findCreditManager ( ca . creditManager ) ;
332+
333+ return bots . map ( bot => {
334+ return {
335+ abi : isV300 ( cm . creditFacade . version )
336+ ? iBotListV300Abi
337+ : iBotListV310Abi ,
338+ address : cm . creditFacade . botList ,
339+ functionName : "getBotStatus" ,
340+ args : isV300 ( cm . creditFacade . version )
341+ ? [ bot , ca . creditManager , ca . creditAccount ]
342+ : [ bot , ca . creditAccount ] ,
343+ } as const ;
344+ } ) ;
345+ } ) ,
346+ allowFailure : true ,
347+ } ) ;
348+
349+ const botsByCAIndex = accountsToCheck . reduce <
350+ Array < Omit < NonNullable < GetConnectedMigrationBotsResult > , "botAddress" > >
351+ > ( ( acc , _ , index ) => {
352+ const r = result . slice ( index * bots . length , ( index + 1 ) * bots . length ) ;
353+
354+ acc . push ( {
355+ result : r ,
356+ } ) ;
357+
358+ return acc ;
359+ } , [ ] ) ;
360+
361+ return botsByCAIndex ;
314362 }
315363 private async getActiveMigrationBots (
316364 accountsToCheck : Array < { creditAccount : Address ; creditManager : Address } > ,
317- legacyMigrationBot : Address | undefined ,
365+ bot : Address | undefined ,
318366 ) {
319- if ( legacyMigrationBot ) {
367+ if ( bot ) {
320368 const result = await this . client . multicall ( {
321369 contracts : accountsToCheck . map ( ca => {
322370 const cm = this . sdk . marketRegister . findCreditManager (
@@ -330,14 +378,14 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
330378 address : cm . creditFacade . botList ,
331379 functionName : "getBotStatus" ,
332380 args : isV300 ( cm . creditFacade . version )
333- ? [ legacyMigrationBot , ca . creditManager , ca . creditAccount ]
334- : [ legacyMigrationBot , ca . creditAccount ] ,
381+ ? [ bot , ca . creditManager , ca . creditAccount ]
382+ : [ bot , ca . creditAccount ] ,
335383 } as const ;
336384 } ) ,
337385 allowFailure : true ,
338386 } ) ;
339387
340- return { result, botAddress : legacyMigrationBot } ;
388+ return { result, botAddress : bot } ;
341389 }
342390
343391 return undefined ;
0 commit comments