Skip to content

Commit 546e4c2

Browse files
committed
fix: return connect bot calls without ca
1 parent 74dc315 commit 546e4c2

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

src/sdk/accounts/CreditAccountsServiceV310.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { PERMISSION_BY_TYPE } from "./constants.js";
77
import type {
88
ClaimFarmRewardsProps,
99
CreditAccountOperationResult,
10+
CreditManagerOperationResult,
1011
ICreditAccountsService,
1112
RepayAndLiquidateCreditAccountProps,
1213
RepayCreditAccountProps,
@@ -26,17 +27,24 @@ export class CreditAccountServiceV310
2627
botBaseType,
2728
stopBot,
2829

29-
creditAccount: ca,
30-
}: SetBotProps): Promise<CreditAccountOperationResult> {
31-
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
30+
targetContract,
31+
}: SetBotProps): Promise<
32+
CreditAccountOperationResult | CreditManagerOperationResult
33+
> {
34+
const cm = this.sdk.marketRegister.findCreditManager(
35+
targetContract.creditManager,
36+
);
3237

33-
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
34-
creditManager: ca.creditManager,
35-
creditAccount: ca,
36-
});
38+
const priceUpdatesCalls =
39+
targetContract.type === "creditAccount"
40+
? await this.getPriceUpdatesForFacade({
41+
creditManager: targetContract.creditManager,
42+
creditAccount: targetContract,
43+
})
44+
: [];
3745

3846
const addBotCall: MultiCall = {
39-
target: ca.creditFacade,
47+
target: cm.creditFacade.address,
4048
callData: encodeFunctionData({
4149
abi: iCreditFacadeMulticallV310Abi,
4250
functionName: "setBotPermissions",
@@ -46,7 +54,10 @@ export class CreditAccountServiceV310
4654

4755
const calls = [...priceUpdatesCalls, addBotCall];
4856

49-
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
57+
const tx =
58+
targetContract.type === "creditAccount"
59+
? cm.creditFacade.multicall(targetContract.creditAccount, calls)
60+
: undefined;
5061

5162
return { tx, calls, creditFacade: cm.creditFacade };
5263
}

src/sdk/accounts/types.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export interface CreditAccountOperationResult {
8080
creditFacade: CreditSuite["creditFacade"];
8181
}
8282

83+
export interface CreditManagerOperationResult {
84+
calls: Array<MultiCall>;
85+
creditFacade: CreditSuite["creditFacade"];
86+
}
87+
8388
export type CloseOptions = "close" | "zeroDebt";
8489

8590
export interface CloseCreditAccountProps {
@@ -443,6 +448,12 @@ export type LiquidationBotType = Exclude<
443448
>;
444449
export type { MigrationBotType };
445450

451+
interface CMSlice {
452+
creditManager: Address;
453+
creditFacade: Address;
454+
type: "creditManager";
455+
}
456+
446457
export interface SetBotProps {
447458
/**
448459
* Address of a bot that is being updated
@@ -457,9 +468,11 @@ export interface SetBotProps {
457468
*/
458469
stopBot: boolean;
459470
/**
460-
* Minimal credit account data {@link RouterCASlice} on which operation is performed
471+
* Minimal credit account data {@link RouterCASlice} on which operation is performed; if omitted, credit manager data is used
472+
* Minimal credit manager data {@link CMSlice} on which operation is performed; used only if credit account is omitted
473+
* At least one of credit account or credit manager must be provided
461474
*/
462-
creditAccount: RouterCASlice;
475+
targetContract: (RouterCASlice & { type: "creditAccount" }) | CMSlice;
463476
}
464477

465478
export type GetConnectedBotsResult = Array<
@@ -546,7 +559,9 @@ export interface ICreditAccountsService extends SDKConstruct {
546559
* @param props - {@link SetBotProps}
547560
* @return All necessary data to execute the transaction (call, credit facade)
548561
*/
549-
setBot: (props: SetBotProps) => Promise<CreditAccountOperationResult>;
562+
setBot: (
563+
props: SetBotProps,
564+
) => Promise<CreditAccountOperationResult | CreditManagerOperationResult>;
550565

551566
/**
552567
* Generates transaction to liquidate credit account

0 commit comments

Comments
 (0)