@gearbox-protocol/sdk 11.12.0 → 11.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,13 +60,10 @@ const LEGACY_MIGRATION_BOT = {
60
60
  address: ACCOUNT_MIGRATOR_BOT,
61
61
  previewer: ACCOUNT_MIGRATOR_PREVIEWER,
62
62
  version: 310,
63
- botType: "MIGRATION_BOT"
63
+ baseType: "LEGACY_MIGRATION"
64
64
  };
65
65
  const PERMISSION_BY_TYPE = {
66
- LIQUIDATION_PROTECTION: BigInt(
67
- import_sdk.BotPermissions.ADD_COLLATERAL | import_sdk.BotPermissions.WITHDRAW_COLLATERAL | import_sdk.BotPermissions.DECREASE_DEBT
68
- ),
69
- MIGRATION: BigInt(
66
+ LEGACY_MIGRATION: BigInt(
70
67
  import_sdk.BotPermissions.EXTERNAL_CALLS | import_sdk.BotPermissions.UPDATE_QUOTA | import_sdk.BotPermissions.DECREASE_DEBT
71
68
  )
72
69
  };
@@ -19,8 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var types_exports = {};
20
20
  __export(types_exports, {
21
21
  BOT_PARAMS_ABI: () => BOT_PARAMS_ABI,
22
- BOT_PARTIAL_LIQUIDATION: () => BOT_PARTIAL_LIQUIDATION,
23
- MIGRATION_BOT_TYPES: () => MIGRATION_BOT_TYPES
22
+ BOT_PARTIAL_LIQUIDATION: () => BOT_PARTIAL_LIQUIDATION
24
23
  });
25
24
  module.exports = __toCommonJS(types_exports);
26
25
  const BOT_PARTIAL_LIQUIDATION = "BOT::PARTIAL_LIQUIDATION";
@@ -31,10 +30,8 @@ const BOT_PARAMS_ABI = [
31
30
  { type: "uint16", name: "premiumScaleFactor" },
32
31
  { type: "uint16", name: "feeScaleFactor" }
33
32
  ];
34
- const MIGRATION_BOT_TYPES = ["MIGRATION_BOT"];
35
33
  // Annotate the CommonJS export names for ESM import in node:
36
34
  0 && (module.exports = {
37
35
  BOT_PARAMS_ABI,
38
- BOT_PARTIAL_LIQUIDATION,
39
- MIGRATION_BOT_TYPES
36
+ BOT_PARTIAL_LIQUIDATION
40
37
  });
@@ -205,12 +205,12 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
205
205
  }
206
206
  /**
207
207
  * Method to get all connected bots for credit account
208
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
208
+ * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
209
209
  and their credit managers to check connected bots on
210
210
  * @returns call result of getConnectedBots for each credit account
211
211
  */
212
- async getConnectedBots(accountsToCheck, legacyMigrationBot) {
213
- const [resp, migration] = await Promise.all([
212
+ async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
213
+ const [resp, migration, additional] = await Promise.all([
214
214
  this.client.multicall({
215
215
  contracts: accountsToCheck.map((o) => {
216
216
  const pool = this.sdk.marketRegister.findByCreditManager(
@@ -225,12 +225,41 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
225
225
  }),
226
226
  allowFailure: true
227
227
  }),
228
- this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot)
228
+ this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot),
229
+ this.getActiveBots(accountsToCheck, additionalBots)
229
230
  ]);
230
- return { legacy: resp, legacyMigration: migration };
231
+ return {
232
+ legacy: resp,
233
+ additionalBots: additional,
234
+ legacyMigration: migration
235
+ };
236
+ }
237
+ async getActiveBots(accountsToCheck, bots) {
238
+ const result = await this.client.multicall({
239
+ contracts: accountsToCheck.flatMap((ca) => {
240
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
241
+ return bots.map((bot) => {
242
+ return {
243
+ abi: (0, import_constants.isV300)(cm.creditFacade.version) ? import_v300.iBotListV300Abi : import_generated.iBotListV310Abi,
244
+ address: cm.creditFacade.botList,
245
+ functionName: "getBotStatus",
246
+ args: (0, import_constants.isV300)(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
247
+ };
248
+ });
249
+ }),
250
+ allowFailure: true
251
+ });
252
+ const botsByCAIndex = accountsToCheck.reduce((acc, _, index) => {
253
+ const r = result.slice(index * bots.length, (index + 1) * bots.length);
254
+ acc.push({
255
+ result: r
256
+ });
257
+ return acc;
258
+ }, []);
259
+ return botsByCAIndex;
231
260
  }
232
- async getActiveMigrationBots(accountsToCheck, legacyMigrationBot) {
233
- if (legacyMigrationBot) {
261
+ async getActiveMigrationBots(accountsToCheck, bot) {
262
+ if (bot) {
234
263
  const result = await this.client.multicall({
235
264
  contracts: accountsToCheck.map((ca) => {
236
265
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -240,12 +269,12 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
240
269
  abi: (0, import_constants.isV300)(cm.creditFacade.version) ? import_v300.iBotListV300Abi : import_generated.iBotListV310Abi,
241
270
  address: cm.creditFacade.botList,
242
271
  functionName: "getBotStatus",
243
- args: (0, import_constants.isV300)(cm.creditFacade.version) ? [legacyMigrationBot, ca.creditManager, ca.creditAccount] : [legacyMigrationBot, ca.creditAccount]
272
+ args: (0, import_constants.isV300)(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
244
273
  };
245
274
  }),
246
275
  allowFailure: true
247
276
  });
248
- return { result, botAddress: legacyMigrationBot };
277
+ return { result, botAddress: bot };
249
278
  }
250
279
  return void 0;
251
280
  }
@@ -31,7 +31,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
31
31
  */
32
32
  async setBot({
33
33
  botAddress,
34
- permissions,
34
+ permissions: defaultPermissions,
35
35
  targetContract
36
36
  }) {
37
37
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -41,6 +41,21 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
41
41
  creditManager: targetContract.creditManager,
42
42
  creditAccount: targetContract
43
43
  }) : [];
44
+ const permissions = defaultPermissions !== null ? defaultPermissions : await (0, import_viem.getContract)({
45
+ address: botAddress,
46
+ client: this.sdk.client,
47
+ abi: [
48
+ {
49
+ type: "function",
50
+ name: "requiredPermissions",
51
+ inputs: [],
52
+ outputs: [
53
+ { name: "", type: "uint192", internalType: "uint192" }
54
+ ],
55
+ stateMutability: "view"
56
+ }
57
+ ]
58
+ }).read.requiredPermissions();
44
59
  const addBotCall = {
45
60
  target: cm.creditFacade.address,
46
61
  callData: (0, import_viem.encodeFunctionData)({
@@ -33,13 +33,10 @@ const LEGACY_MIGRATION_BOT = {
33
33
  address: ACCOUNT_MIGRATOR_BOT,
34
34
  previewer: ACCOUNT_MIGRATOR_PREVIEWER,
35
35
  version: 310,
36
- botType: "MIGRATION_BOT"
36
+ baseType: "LEGACY_MIGRATION"
37
37
  };
38
38
  const PERMISSION_BY_TYPE = {
39
- LIQUIDATION_PROTECTION: BigInt(
40
- BotPermissions.ADD_COLLATERAL | BotPermissions.WITHDRAW_COLLATERAL | BotPermissions.DECREASE_DEBT
41
- ),
42
- MIGRATION: BigInt(
39
+ LEGACY_MIGRATION: BigInt(
43
40
  BotPermissions.EXTERNAL_CALLS | BotPermissions.UPDATE_QUOTA | BotPermissions.DECREASE_DEBT
44
41
  )
45
42
  };
@@ -6,9 +6,7 @@ const BOT_PARAMS_ABI = [
6
6
  { type: "uint16", name: "premiumScaleFactor" },
7
7
  { type: "uint16", name: "feeScaleFactor" }
8
8
  ];
9
- const MIGRATION_BOT_TYPES = ["MIGRATION_BOT"];
10
9
  export {
11
10
  BOT_PARAMS_ABI,
12
- BOT_PARTIAL_LIQUIDATION,
13
- MIGRATION_BOT_TYPES
11
+ BOT_PARTIAL_LIQUIDATION
14
12
  };
@@ -195,12 +195,12 @@ class AbstractCreditAccountService extends SDKConstruct {
195
195
  }
196
196
  /**
197
197
  * Method to get all connected bots for credit account
198
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
198
+ * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
199
199
  and their credit managers to check connected bots on
200
200
  * @returns call result of getConnectedBots for each credit account
201
201
  */
202
- async getConnectedBots(accountsToCheck, legacyMigrationBot) {
203
- const [resp, migration] = await Promise.all([
202
+ async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
203
+ const [resp, migration, additional] = await Promise.all([
204
204
  this.client.multicall({
205
205
  contracts: accountsToCheck.map((o) => {
206
206
  const pool = this.sdk.marketRegister.findByCreditManager(
@@ -215,12 +215,41 @@ class AbstractCreditAccountService extends SDKConstruct {
215
215
  }),
216
216
  allowFailure: true
217
217
  }),
218
- this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot)
218
+ this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot),
219
+ this.getActiveBots(accountsToCheck, additionalBots)
219
220
  ]);
220
- return { legacy: resp, legacyMigration: migration };
221
+ return {
222
+ legacy: resp,
223
+ additionalBots: additional,
224
+ legacyMigration: migration
225
+ };
226
+ }
227
+ async getActiveBots(accountsToCheck, bots) {
228
+ const result = await this.client.multicall({
229
+ contracts: accountsToCheck.flatMap((ca) => {
230
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
231
+ return bots.map((bot) => {
232
+ return {
233
+ abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
234
+ address: cm.creditFacade.botList,
235
+ functionName: "getBotStatus",
236
+ args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
237
+ };
238
+ });
239
+ }),
240
+ allowFailure: true
241
+ });
242
+ const botsByCAIndex = accountsToCheck.reduce((acc, _, index) => {
243
+ const r = result.slice(index * bots.length, (index + 1) * bots.length);
244
+ acc.push({
245
+ result: r
246
+ });
247
+ return acc;
248
+ }, []);
249
+ return botsByCAIndex;
221
250
  }
222
- async getActiveMigrationBots(accountsToCheck, legacyMigrationBot) {
223
- if (legacyMigrationBot) {
251
+ async getActiveMigrationBots(accountsToCheck, bot) {
252
+ if (bot) {
224
253
  const result = await this.client.multicall({
225
254
  contracts: accountsToCheck.map((ca) => {
226
255
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -230,12 +259,12 @@ class AbstractCreditAccountService extends SDKConstruct {
230
259
  abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
231
260
  address: cm.creditFacade.botList,
232
261
  functionName: "getBotStatus",
233
- args: isV300(cm.creditFacade.version) ? [legacyMigrationBot, ca.creditManager, ca.creditAccount] : [legacyMigrationBot, ca.creditAccount]
262
+ args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
234
263
  };
235
264
  }),
236
265
  allowFailure: true
237
266
  });
238
- return { result, botAddress: legacyMigrationBot };
267
+ return { result, botAddress: bot };
239
268
  }
240
269
  return void 0;
241
270
  }
@@ -1,4 +1,4 @@
1
- import { encodeFunctionData } from "viem";
1
+ import { encodeFunctionData, getContract } from "viem";
2
2
  import { iCreditFacadeMulticallV310Abi } from "../../abi/310/generated.js";
3
3
  import { MAX_UINT256 } from "../constants/math.js";
4
4
  import { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
@@ -8,7 +8,7 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
8
8
  */
9
9
  async setBot({
10
10
  botAddress,
11
- permissions,
11
+ permissions: defaultPermissions,
12
12
  targetContract
13
13
  }) {
14
14
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -18,6 +18,21 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
18
18
  creditManager: targetContract.creditManager,
19
19
  creditAccount: targetContract
20
20
  }) : [];
21
+ const permissions = defaultPermissions !== null ? defaultPermissions : await getContract({
22
+ address: botAddress,
23
+ client: this.sdk.client,
24
+ abi: [
25
+ {
26
+ type: "function",
27
+ name: "requiredPermissions",
28
+ inputs: [],
29
+ outputs: [
30
+ { name: "", type: "uint192", internalType: "uint192" }
31
+ ],
32
+ stateMutability: "view"
33
+ }
34
+ ]
35
+ }).read.requiredPermissions();
21
36
  const addBotCall = {
22
37
  target: cm.creditFacade.address,
23
38
  callData: encodeFunctionData({
@@ -5,4 +5,4 @@ export declare const PARTIAL_LIQUIDATION_BOT_CONFIGS: Partial<Record<NetworkType
5
5
  export declare const PARTIAL_LIQUIDATION_BOT_SALT = "GEARBOX";
6
6
  export declare const PARTIAL_LIQUIDATION_BOT_DEPLOYER: Address;
7
7
  export declare const LEGACY_MIGRATION_BOT: MigrationBotState;
8
- export declare const PERMISSION_BY_TYPE: Record<BotBaseType, bigint>;
8
+ export declare const PERMISSION_BY_TYPE: Record<Extract<BotBaseType, "LEGACY_MIGRATION">, bigint>;
@@ -40,12 +40,10 @@ export interface BotsPluginStateHuman {
40
40
  export interface BotsPluginState {
41
41
  bots: BotState[];
42
42
  }
43
- export type BotBaseType = "LIQUIDATION_PROTECTION" | "MIGRATION";
44
- export declare const MIGRATION_BOT_TYPES: readonly ["MIGRATION_BOT"];
45
- export type MigrationBotType = (typeof MIGRATION_BOT_TYPES)[number];
43
+ export type BotBaseType = "LIQUIDATION_PROTECTION" | "LEGACY_MIGRATION";
46
44
  export type MigrationBotState = {
47
45
  address: Address;
48
46
  version: 310;
49
47
  previewer: Address;
50
- botType: MigrationBotType;
48
+ baseType: Extract<BotBaseType, "LEGACY_MIGRATION">;
51
49
  };
@@ -5,7 +5,7 @@ import type { GearboxSDK } from "../GearboxSDK.js";
5
5
  import type { OnDemandPriceUpdates, PriceUpdateV300, PriceUpdateV310, UpdatePriceFeedsResult } from "../market/index.js";
6
6
  import { type Asset, type RouterCASlice } from "../router/index.js";
7
7
  import type { MultiCall } from "../types/index.js";
8
- import type { AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, PriceUpdatesOptions, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
8
+ import type { AccountToCheck, AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, PriceUpdatesOptions, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
9
9
  export interface CreditAccountServiceOptions {
10
10
  batchSize?: number;
11
11
  }
@@ -39,17 +39,16 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
39
39
  getRewards(creditAccount: Address): Promise<Array<Rewards>>;
40
40
  /**
41
41
  * Method to get all connected bots for credit account
42
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
42
+ * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
43
43
  and their credit managers to check connected bots on
44
44
  * @returns call result of getConnectedBots for each credit account
45
45
  */
46
- getConnectedBots(accountsToCheck: Array<{
47
- creditAccount: Address;
48
- creditManager: Address;
49
- }>, legacyMigrationBot: Address | undefined): Promise<{
46
+ getConnectedBots(accountsToCheck: Array<AccountToCheck>, legacyMigrationBot: Address | undefined, additionalBots: Array<Address>): Promise<{
50
47
  legacy: GetConnectedBotsResult;
51
48
  legacyMigration: GetConnectedMigrationBotsResult;
49
+ additionalBots: Array<Omit<NonNullable<GetConnectedMigrationBotsResult>, "botAddress">>;
52
50
  }>;
51
+ private getActiveBots;
53
52
  private getActiveMigrationBots;
54
53
  /**
55
54
  * Generates transaction to liquidate credit account
@@ -4,7 +4,7 @@ export declare class CreditAccountServiceV310 extends AbstractCreditAccountServi
4
4
  /**
5
5
  * Implements {@link ICreditAccountsService.setBot}
6
6
  */
7
- setBot({ botAddress, permissions, targetContract, }: SetBotProps): Promise<CreditAccountOperationResult | CreditManagerOperationResult>;
7
+ setBot({ botAddress, permissions: defaultPermissions, targetContract, }: SetBotProps): Promise<CreditAccountOperationResult | CreditManagerOperationResult>;
8
8
  /**
9
9
  * Implements {@link ICreditAccountsService.withdrawCollateral}
10
10
  */
@@ -164,6 +164,10 @@ export interface WithdrawCollateralProps extends PrepareUpdateQuotasProps {
164
164
  */
165
165
  creditAccount: RouterCASlice;
166
166
  }
167
+ export type AccountToCheck = {
168
+ creditAccount: Address;
169
+ creditManager: Address;
170
+ };
167
171
  export interface ExecuteSwapProps extends PrepareUpdateQuotasProps {
168
172
  /**
169
173
  * Array of MultiCall from router methods getSingleSwap or getAllSwaps
@@ -376,7 +380,7 @@ export interface SetBotProps {
376
380
  /**
377
381
  * Permissions to set for the bot
378
382
  */
379
- permissions: bigint;
383
+ permissions: bigint | null;
380
384
  /**
381
385
  * Minimal credit account data {@link RouterCASlice} on which operation is performed; if omitted, credit manager data is used
382
386
  * Minimal credit manager data {@link CMSlice} on which operation is performed; used only if credit account is omitted
@@ -434,17 +438,15 @@ export interface ICreditAccountsService extends SDKConstruct {
434
438
  getRewards(creditAccount: Address): Promise<Array<Rewards>>;
435
439
  /**
436
440
  * Method to get all connected bots for credit account
437
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
441
+ * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
438
442
  * @param {Address | undefined} legacyMigrationBot - address of the bot to check connected bots on
439
443
  * and their credit managers to check connected bots on
440
444
  * @returns call result of getConnectedBots for each credit account
441
445
  */
442
- getConnectedBots(accountsToCheck: Array<{
443
- creditAccount: Address;
444
- creditManager: Address;
445
- }>, legacyMigrationBot: Address | undefined): Promise<{
446
+ getConnectedBots(accountsToCheck: Array<AccountToCheck>, legacyMigrationBot: Address | undefined, additionalBots: Array<Address>): Promise<{
446
447
  legacy: GetConnectedBotsResult;
447
448
  legacyMigration: GetConnectedMigrationBotsResult;
449
+ additionalBots: Array<Omit<NonNullable<GetConnectedMigrationBotsResult>, "botAddress">>;
448
450
  }>;
449
451
  /**
450
452
  * V3.1 method, throws in V3. Connects/disables a bot and updates prices
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "11.12.0",
3
+ "version": "11.12.1",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",