@gearbox-protocol/sdk 12.0.0-next.7 → 12.0.0

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.
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var loss_policy_factory_exports = {};
20
+ __export(loss_policy_factory_exports, {
21
+ LossPolicyFactory: () => LossPolicyFactory
22
+ });
23
+ module.exports = __toCommonJS(loss_policy_factory_exports);
24
+ var import_viem = require("viem");
25
+ var import_generated = require("../../../abi/310/generated.js");
26
+ var import_types = require("../types.js");
27
+ var import_abstract_factory = require("./abstract-factory.js");
28
+ const abi = import_generated.iLossPolicyV310Abi;
29
+ class LossPolicyFactory extends import_abstract_factory.AbstractFactory {
30
+ constructor() {
31
+ super(abi);
32
+ }
33
+ setAccessMode(args) {
34
+ return this.createCallData({
35
+ functionName: "setAccessMode",
36
+ args: [args.accessMode]
37
+ });
38
+ }
39
+ setChecksEnabled(args) {
40
+ return this.createCallData({
41
+ functionName: "setChecksEnabled",
42
+ args: [args.enabled]
43
+ });
44
+ }
45
+ decodeConfig(calldata) {
46
+ const decoded = (0, import_viem.decodeFunctionData)({
47
+ abi: this.abi,
48
+ data: calldata
49
+ });
50
+ if (decoded.functionName === "setAccessMode") {
51
+ const [accessMode] = decoded.args;
52
+ return {
53
+ functionName: decoded.functionName,
54
+ args: {
55
+ mode: import_types.AccessMode[accessMode] ?? accessMode
56
+ }
57
+ };
58
+ }
59
+ return super.decodeConfig(calldata);
60
+ }
61
+ }
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ LossPolicyFactory
65
+ });
@@ -29,6 +29,7 @@ var import_plugins = require("../plugins/index.js");
29
29
  var import_create2 = require("../utils/create2.js");
30
30
  var import_utils = require("../utils/index.js");
31
31
  var import_credit_factory = require("./factory/credit-factory.js");
32
+ var import_loss_policy_factory = require("./factory/loss-policy-factory.js");
32
33
  var import_pool_factory = require("./factory/pool-factory.js");
33
34
  var import_price_oracle_factory = require("./factory/price-oracle-factory.js");
34
35
  var import_index = require("./index.js");
@@ -37,11 +38,13 @@ class MarketConfiguratorContract extends import_sdk.BaseContract {
37
38
  creditFactory;
38
39
  poolFactory;
39
40
  priceOracleFactory;
41
+ lossPolicyFactory;
40
42
  constructor(addr, client) {
41
43
  super({ client }, { abi, addr, name: "MarketConfigurator" });
42
44
  this.creditFactory = new import_credit_factory.CreditFactory();
43
45
  this.poolFactory = new import_pool_factory.PoolFactory();
44
46
  this.priceOracleFactory = new import_price_oracle_factory.PriceOracleFactory();
47
+ this.lossPolicyFactory = new import_loss_policy_factory.LossPolicyFactory();
45
48
  }
46
49
  async getAddressProvider() {
47
50
  const addressProvider = await this.contract.read.addressProvider();
@@ -398,6 +401,22 @@ class MarketConfiguratorContract extends import_sdk.BaseContract {
398
401
  ]),
399
402
  functionName: "getRoleHolders",
400
403
  args: [(0, import_viem.stringToHex)("UNPAUSABLE_ADMIN", { size: 32 })]
404
+ },
405
+ {
406
+ address: acl,
407
+ abi: (0, import_viem.parseAbi)([
408
+ "function getRoleHolders(bytes32) view returns (address[])"
409
+ ]),
410
+ functionName: "getRoleHolders",
411
+ args: [(0, import_viem.stringToHex)("LOSS_LIQUIDATOR", { size: 32 })]
412
+ },
413
+ {
414
+ address: acl,
415
+ abi: (0, import_viem.parseAbi)([
416
+ "function getRoleHolders(bytes32) view returns (address[])"
417
+ ]),
418
+ functionName: "getRoleHolders",
419
+ args: [(0, import_viem.stringToHex)("EMERGENCY_LIQUIDATOR", { size: 32 })]
401
420
  }
402
421
  ]
403
422
  });
@@ -406,7 +425,9 @@ class MarketConfiguratorContract extends import_sdk.BaseContract {
406
425
  emergencyAdmin,
407
426
  treasury,
408
427
  pausableAdmins: [...results[0]],
409
- unpausableAdmins: [...results[1]]
428
+ unpausableAdmins: [...results[1]],
429
+ lossLiquidators: [...results[2]],
430
+ emergencyLiquidators: [...results[3]]
410
431
  };
411
432
  }
412
433
  async multipause() {
@@ -645,6 +666,14 @@ class MarketConfiguratorContract extends import_sdk.BaseContract {
645
666
  calldata
646
667
  };
647
668
  }
669
+ case "configureLossPolicy": {
670
+ const [pool, calldata] = args;
671
+ const decoded = this.lossPolicyFactory.decodeConfig(calldata);
672
+ return {
673
+ pool,
674
+ data: (0, import_sdk.json_stringify)(decoded)
675
+ };
676
+ }
648
677
  case "updateInterestRateModel": {
649
678
  const [pool, deployParams] = args;
650
679
  return {
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -13,4 +17,17 @@ var __copyProps = (to, from, except, desc) => {
13
17
  };
14
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
19
  var types_exports = {};
20
+ __export(types_exports, {
21
+ AccessMode: () => AccessMode
22
+ });
16
23
  module.exports = __toCommonJS(types_exports);
24
+ var AccessMode = /* @__PURE__ */ ((AccessMode2) => {
25
+ AccessMode2[AccessMode2["Permissionless"] = 0] = "Permissionless";
26
+ AccessMode2[AccessMode2["Permissioned"] = 1] = "Permissioned";
27
+ AccessMode2[AccessMode2["Forbidden"] = 2] = "Forbidden";
28
+ return AccessMode2;
29
+ })(AccessMode || {});
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ AccessMode
33
+ });
@@ -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
  });
@@ -203,12 +203,12 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
203
203
  }
204
204
  /**
205
205
  * Method to get all connected bots for credit account
206
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
206
+ * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
207
207
  and their credit managers to check connected bots on
208
208
  * @returns call result of getConnectedBots for each credit account
209
209
  */
210
- async getConnectedBots(accountsToCheck, legacyMigrationBot) {
211
- const [resp, migration] = await Promise.all([
210
+ async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
211
+ const [resp, migration, additional] = await Promise.all([
212
212
  this.client.multicall({
213
213
  contracts: accountsToCheck.map((o) => {
214
214
  const pool = this.sdk.marketRegister.findByCreditManager(
@@ -223,12 +223,41 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
223
223
  }),
224
224
  allowFailure: true
225
225
  }),
226
- this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot)
226
+ this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot),
227
+ this.getActiveBots(accountsToCheck, additionalBots)
227
228
  ]);
228
- return { legacy: resp, legacyMigration: migration };
229
+ return {
230
+ legacy: resp,
231
+ additionalBots: additional,
232
+ legacyMigration: migration
233
+ };
234
+ }
235
+ async getActiveBots(accountsToCheck, bots) {
236
+ const result = await this.client.multicall({
237
+ contracts: accountsToCheck.flatMap((ca) => {
238
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
239
+ return bots.map((bot) => {
240
+ return {
241
+ abi: (0, import_constants.isV300)(cm.creditFacade.version) ? import_v300.iBotListV300Abi : import_generated.iBotListV310Abi,
242
+ address: cm.creditFacade.botList,
243
+ functionName: "getBotStatus",
244
+ args: (0, import_constants.isV300)(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
245
+ };
246
+ });
247
+ }),
248
+ allowFailure: true
249
+ });
250
+ const botsByCAIndex = accountsToCheck.reduce((acc, _, index) => {
251
+ const r = result.slice(index * bots.length, (index + 1) * bots.length);
252
+ acc.push({
253
+ result: r
254
+ });
255
+ return acc;
256
+ }, []);
257
+ return botsByCAIndex;
229
258
  }
230
- async getActiveMigrationBots(accountsToCheck, legacyMigrationBot) {
231
- if (legacyMigrationBot) {
259
+ async getActiveMigrationBots(accountsToCheck, bot) {
260
+ if (bot) {
232
261
  const result = await this.client.multicall({
233
262
  contracts: accountsToCheck.map((ca) => {
234
263
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -238,12 +267,12 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
238
267
  abi: (0, import_constants.isV300)(cm.creditFacade.version) ? import_v300.iBotListV300Abi : import_generated.iBotListV310Abi,
239
268
  address: cm.creditFacade.botList,
240
269
  functionName: "getBotStatus",
241
- args: (0, import_constants.isV300)(cm.creditFacade.version) ? [legacyMigrationBot, ca.creditManager, ca.creditAccount] : [legacyMigrationBot, ca.creditAccount]
270
+ args: (0, import_constants.isV300)(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
242
271
  };
243
272
  }),
244
273
  allowFailure: true
245
274
  });
246
- return { result, botAddress: legacyMigrationBot };
275
+ return { result, botAddress: bot };
247
276
  }
248
277
  return void 0;
249
278
  }
@@ -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)({
@@ -0,0 +1,41 @@
1
+ import { decodeFunctionData } from "viem";
2
+ import { iLossPolicyV310Abi } from "../../../abi/310/generated.js";
3
+ import { AccessMode } from "../types.js";
4
+ import { AbstractFactory } from "./abstract-factory.js";
5
+ const abi = iLossPolicyV310Abi;
6
+ class LossPolicyFactory extends AbstractFactory {
7
+ constructor() {
8
+ super(abi);
9
+ }
10
+ setAccessMode(args) {
11
+ return this.createCallData({
12
+ functionName: "setAccessMode",
13
+ args: [args.accessMode]
14
+ });
15
+ }
16
+ setChecksEnabled(args) {
17
+ return this.createCallData({
18
+ functionName: "setChecksEnabled",
19
+ args: [args.enabled]
20
+ });
21
+ }
22
+ decodeConfig(calldata) {
23
+ const decoded = decodeFunctionData({
24
+ abi: this.abi,
25
+ data: calldata
26
+ });
27
+ if (decoded.functionName === "setAccessMode") {
28
+ const [accessMode] = decoded.args;
29
+ return {
30
+ functionName: decoded.functionName,
31
+ args: {
32
+ mode: AccessMode[accessMode] ?? accessMode
33
+ }
34
+ };
35
+ }
36
+ return super.decodeConfig(calldata);
37
+ }
38
+ }
39
+ export {
40
+ LossPolicyFactory
41
+ };
@@ -24,6 +24,7 @@ import {
24
24
  import { handleSalt } from "../utils/create2.js";
25
25
  import { convertPercent } from "../utils/index.js";
26
26
  import { CreditFactory } from "./factory/credit-factory.js";
27
+ import { LossPolicyFactory } from "./factory/loss-policy-factory.js";
27
28
  import { PoolFactory } from "./factory/pool-factory.js";
28
29
  import { PriceOracleFactory } from "./factory/price-oracle-factory.js";
29
30
  import { AddressProviderContract } from "./index.js";
@@ -32,11 +33,13 @@ class MarketConfiguratorContract extends BaseContract {
32
33
  creditFactory;
33
34
  poolFactory;
34
35
  priceOracleFactory;
36
+ lossPolicyFactory;
35
37
  constructor(addr, client) {
36
38
  super({ client }, { abi, addr, name: "MarketConfigurator" });
37
39
  this.creditFactory = new CreditFactory();
38
40
  this.poolFactory = new PoolFactory();
39
41
  this.priceOracleFactory = new PriceOracleFactory();
42
+ this.lossPolicyFactory = new LossPolicyFactory();
40
43
  }
41
44
  async getAddressProvider() {
42
45
  const addressProvider = await this.contract.read.addressProvider();
@@ -393,6 +396,22 @@ class MarketConfiguratorContract extends BaseContract {
393
396
  ]),
394
397
  functionName: "getRoleHolders",
395
398
  args: [stringToHex("UNPAUSABLE_ADMIN", { size: 32 })]
399
+ },
400
+ {
401
+ address: acl,
402
+ abi: parseAbi([
403
+ "function getRoleHolders(bytes32) view returns (address[])"
404
+ ]),
405
+ functionName: "getRoleHolders",
406
+ args: [stringToHex("LOSS_LIQUIDATOR", { size: 32 })]
407
+ },
408
+ {
409
+ address: acl,
410
+ abi: parseAbi([
411
+ "function getRoleHolders(bytes32) view returns (address[])"
412
+ ]),
413
+ functionName: "getRoleHolders",
414
+ args: [stringToHex("EMERGENCY_LIQUIDATOR", { size: 32 })]
396
415
  }
397
416
  ]
398
417
  });
@@ -401,7 +420,9 @@ class MarketConfiguratorContract extends BaseContract {
401
420
  emergencyAdmin,
402
421
  treasury,
403
422
  pausableAdmins: [...results[0]],
404
- unpausableAdmins: [...results[1]]
423
+ unpausableAdmins: [...results[1]],
424
+ lossLiquidators: [...results[2]],
425
+ emergencyLiquidators: [...results[3]]
405
426
  };
406
427
  }
407
428
  async multipause() {
@@ -640,6 +661,14 @@ class MarketConfiguratorContract extends BaseContract {
640
661
  calldata
641
662
  };
642
663
  }
664
+ case "configureLossPolicy": {
665
+ const [pool, calldata] = args;
666
+ const decoded = this.lossPolicyFactory.decodeConfig(calldata);
667
+ return {
668
+ pool,
669
+ data: json_stringify(decoded)
670
+ };
671
+ }
643
672
  case "updateInterestRateModel": {
644
673
  const [pool, deployParams] = args;
645
674
  return {
@@ -0,0 +1,9 @@
1
+ var AccessMode = /* @__PURE__ */ ((AccessMode2) => {
2
+ AccessMode2[AccessMode2["Permissionless"] = 0] = "Permissionless";
3
+ AccessMode2[AccessMode2["Permissioned"] = 1] = "Permissioned";
4
+ AccessMode2[AccessMode2["Forbidden"] = 2] = "Forbidden";
5
+ return AccessMode2;
6
+ })(AccessMode || {});
7
+ export {
8
+ AccessMode
9
+ };
@@ -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
  };
@@ -193,12 +193,12 @@ class AbstractCreditAccountService extends SDKConstruct {
193
193
  }
194
194
  /**
195
195
  * Method to get all connected bots for credit account
196
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
196
+ * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
197
197
  and their credit managers to check connected bots on
198
198
  * @returns call result of getConnectedBots for each credit account
199
199
  */
200
- async getConnectedBots(accountsToCheck, legacyMigrationBot) {
201
- const [resp, migration] = await Promise.all([
200
+ async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
201
+ const [resp, migration, additional] = await Promise.all([
202
202
  this.client.multicall({
203
203
  contracts: accountsToCheck.map((o) => {
204
204
  const pool = this.sdk.marketRegister.findByCreditManager(
@@ -213,12 +213,41 @@ class AbstractCreditAccountService extends SDKConstruct {
213
213
  }),
214
214
  allowFailure: true
215
215
  }),
216
- this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot)
216
+ this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot),
217
+ this.getActiveBots(accountsToCheck, additionalBots)
217
218
  ]);
218
- return { legacy: resp, legacyMigration: migration };
219
+ return {
220
+ legacy: resp,
221
+ additionalBots: additional,
222
+ legacyMigration: migration
223
+ };
224
+ }
225
+ async getActiveBots(accountsToCheck, bots) {
226
+ const result = await this.client.multicall({
227
+ contracts: accountsToCheck.flatMap((ca) => {
228
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
229
+ return bots.map((bot) => {
230
+ return {
231
+ abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
232
+ address: cm.creditFacade.botList,
233
+ functionName: "getBotStatus",
234
+ args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
235
+ };
236
+ });
237
+ }),
238
+ allowFailure: true
239
+ });
240
+ const botsByCAIndex = accountsToCheck.reduce((acc, _, index) => {
241
+ const r = result.slice(index * bots.length, (index + 1) * bots.length);
242
+ acc.push({
243
+ result: r
244
+ });
245
+ return acc;
246
+ }, []);
247
+ return botsByCAIndex;
219
248
  }
220
- async getActiveMigrationBots(accountsToCheck, legacyMigrationBot) {
221
- if (legacyMigrationBot) {
249
+ async getActiveMigrationBots(accountsToCheck, bot) {
250
+ if (bot) {
222
251
  const result = await this.client.multicall({
223
252
  contracts: accountsToCheck.map((ca) => {
224
253
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -228,12 +257,12 @@ class AbstractCreditAccountService extends SDKConstruct {
228
257
  abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
229
258
  address: cm.creditFacade.botList,
230
259
  functionName: "getBotStatus",
231
- args: isV300(cm.creditFacade.version) ? [legacyMigrationBot, ca.creditManager, ca.creditAccount] : [legacyMigrationBot, ca.creditAccount]
260
+ args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
232
261
  };
233
262
  }),
234
263
  allowFailure: true
235
264
  });
236
- return { result, botAddress: legacyMigrationBot };
265
+ return { result, botAddress: bot };
237
266
  }
238
267
  return void 0;
239
268
  }
@@ -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({
@@ -0,0 +1,143 @@
1
+ import { type Hex } from "viem";
2
+ import { AccessMode } from "../types.js";
3
+ import { AbstractFactory } from "./abstract-factory.js";
4
+ declare const abi: readonly [{
5
+ readonly type: "function";
6
+ readonly name: "accessMode";
7
+ readonly inputs: readonly [];
8
+ readonly outputs: readonly [{
9
+ readonly name: "";
10
+ readonly type: "uint8";
11
+ readonly internalType: "enum ILossPolicy.AccessMode";
12
+ }];
13
+ readonly stateMutability: "view";
14
+ }, {
15
+ readonly type: "function";
16
+ readonly name: "checksEnabled";
17
+ readonly inputs: readonly [];
18
+ readonly outputs: readonly [{
19
+ readonly name: "";
20
+ readonly type: "bool";
21
+ readonly internalType: "bool";
22
+ }];
23
+ readonly stateMutability: "view";
24
+ }, {
25
+ readonly type: "function";
26
+ readonly name: "contractType";
27
+ readonly inputs: readonly [];
28
+ readonly outputs: readonly [{
29
+ readonly name: "";
30
+ readonly type: "bytes32";
31
+ readonly internalType: "bytes32";
32
+ }];
33
+ readonly stateMutability: "view";
34
+ }, {
35
+ readonly type: "function";
36
+ readonly name: "isLiquidatableWithLoss";
37
+ readonly inputs: readonly [{
38
+ readonly name: "creditAccount";
39
+ readonly type: "address";
40
+ readonly internalType: "address";
41
+ }, {
42
+ readonly name: "caller";
43
+ readonly type: "address";
44
+ readonly internalType: "address";
45
+ }, {
46
+ readonly name: "params";
47
+ readonly type: "tuple";
48
+ readonly internalType: "struct ILossPolicy.Params";
49
+ readonly components: readonly [{
50
+ readonly name: "totalDebtUSD";
51
+ readonly type: "uint256";
52
+ readonly internalType: "uint256";
53
+ }, {
54
+ readonly name: "twvUSD";
55
+ readonly type: "uint256";
56
+ readonly internalType: "uint256";
57
+ }, {
58
+ readonly name: "extraData";
59
+ readonly type: "bytes";
60
+ readonly internalType: "bytes";
61
+ }];
62
+ }];
63
+ readonly outputs: readonly [{
64
+ readonly name: "";
65
+ readonly type: "bool";
66
+ readonly internalType: "bool";
67
+ }];
68
+ readonly stateMutability: "nonpayable";
69
+ }, {
70
+ readonly type: "function";
71
+ readonly name: "serialize";
72
+ readonly inputs: readonly [];
73
+ readonly outputs: readonly [{
74
+ readonly name: "serializedData";
75
+ readonly type: "bytes";
76
+ readonly internalType: "bytes";
77
+ }];
78
+ readonly stateMutability: "view";
79
+ }, {
80
+ readonly type: "function";
81
+ readonly name: "setAccessMode";
82
+ readonly inputs: readonly [{
83
+ readonly name: "mode";
84
+ readonly type: "uint8";
85
+ readonly internalType: "enum ILossPolicy.AccessMode";
86
+ }];
87
+ readonly outputs: readonly [];
88
+ readonly stateMutability: "nonpayable";
89
+ }, {
90
+ readonly type: "function";
91
+ readonly name: "setChecksEnabled";
92
+ readonly inputs: readonly [{
93
+ readonly name: "enabled";
94
+ readonly type: "bool";
95
+ readonly internalType: "bool";
96
+ }];
97
+ readonly outputs: readonly [];
98
+ readonly stateMutability: "nonpayable";
99
+ }, {
100
+ readonly type: "function";
101
+ readonly name: "version";
102
+ readonly inputs: readonly [];
103
+ readonly outputs: readonly [{
104
+ readonly name: "";
105
+ readonly type: "uint256";
106
+ readonly internalType: "uint256";
107
+ }];
108
+ readonly stateMutability: "view";
109
+ }, {
110
+ readonly type: "event";
111
+ readonly name: "SetAccessMode";
112
+ readonly inputs: readonly [{
113
+ readonly name: "mode";
114
+ readonly type: "uint8";
115
+ readonly indexed: false;
116
+ readonly internalType: "enum ILossPolicy.AccessMode";
117
+ }];
118
+ readonly anonymous: false;
119
+ }, {
120
+ readonly type: "event";
121
+ readonly name: "SetChecksEnabled";
122
+ readonly inputs: readonly [{
123
+ readonly name: "enabled";
124
+ readonly type: "bool";
125
+ readonly indexed: false;
126
+ readonly internalType: "bool";
127
+ }];
128
+ readonly anonymous: false;
129
+ }];
130
+ export declare class LossPolicyFactory extends AbstractFactory<typeof abi> {
131
+ constructor();
132
+ setAccessMode(args: {
133
+ accessMode: AccessMode;
134
+ }): Hex;
135
+ setChecksEnabled(args: {
136
+ enabled: boolean;
137
+ }): Hex;
138
+ decodeConfig(calldata: Hex): {
139
+ functionName: string;
140
+ args: Record<string, string>;
141
+ } | null;
142
+ }
143
+ export {};
@@ -2,6 +2,7 @@ import { type Address, type Chain, type DecodeFunctionDataReturnType, type Hex,
2
2
  import type { ParsedCallArgs, RawTx } from "../../sdk/index.js";
3
3
  import { BaseContract } from "../../sdk/index.js";
4
4
  import { CreditFactory } from "./factory/credit-factory.js";
5
+ import { LossPolicyFactory } from "./factory/loss-policy-factory.js";
5
6
  import { PoolFactory } from "./factory/pool-factory.js";
6
7
  import { PriceOracleFactory } from "./factory/price-oracle-factory.js";
7
8
  import { AddressProviderContract } from "./index.js";
@@ -1534,6 +1535,7 @@ export declare class MarketConfiguratorContract extends BaseContract<typeof abi>
1534
1535
  readonly creditFactory: CreditFactory;
1535
1536
  readonly poolFactory: PoolFactory;
1536
1537
  readonly priceOracleFactory: PriceOracleFactory;
1538
+ readonly lossPolicyFactory: LossPolicyFactory;
1537
1539
  constructor(addr: Address, client: PublicClient<Transport, Chain>);
1538
1540
  getAddressProvider(): Promise<AddressProviderContract>;
1539
1541
  previewCreateMarket(params: {
@@ -1636,6 +1638,8 @@ export declare class MarketConfiguratorContract extends BaseContract<typeof abi>
1636
1638
  treasury: Address;
1637
1639
  pausableAdmins: Address[];
1638
1640
  unpausableAdmins: Address[];
1641
+ lossLiquidators: Address[];
1642
+ emergencyLiquidators: Address[];
1639
1643
  }>;
1640
1644
  multipause(): Promise<Address | undefined>;
1641
1645
  grantRole(role: string, address: Address): RawTx;
@@ -63,3 +63,8 @@ export interface PriceUpdate {
63
63
  priceFeed: Address;
64
64
  data: Hex;
65
65
  }
66
+ export declare enum AccessMode {
67
+ Permissionless = 0,
68
+ Permissioned = 1,
69
+ Forbidden = 2
70
+ }
@@ -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
@@ -435,17 +439,15 @@ export interface ICreditAccountsService extends Construct {
435
439
  getRewards(creditAccount: Address): Promise<Array<Rewards>>;
436
440
  /**
437
441
  * Method to get all connected bots for credit account
438
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
442
+ * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
439
443
  * @param {Address | undefined} legacyMigrationBot - address of the bot to check connected bots on
440
444
  * and their credit managers to check connected bots on
441
445
  * @returns call result of getConnectedBots for each credit account
442
446
  */
443
- getConnectedBots(accountsToCheck: Array<{
444
- creditAccount: Address;
445
- creditManager: Address;
446
- }>, legacyMigrationBot: Address | undefined): Promise<{
447
+ getConnectedBots(accountsToCheck: Array<AccountToCheck>, legacyMigrationBot: Address | undefined, additionalBots: Array<Address>): Promise<{
447
448
  legacy: GetConnectedBotsResult;
448
449
  legacyMigration: GetConnectedMigrationBotsResult;
450
+ additionalBots: Array<Omit<NonNullable<GetConnectedMigrationBotsResult>, "botAddress">>;
449
451
  }>;
450
452
  /**
451
453
  * V3.1 method, throws in V3. Connects/disables a bot and updates prices
@@ -123,8 +123,8 @@ export declare class CreditAccountData_Legacy {
123
123
  constructor(payload: CreditAccountDataPayload);
124
124
  static sortBalances(balances: Record<Address, bigint>, prices: Record<Address, bigint>, tokens: Record<Address, TokenData>): Array<[Address, bigint]>;
125
125
  static sortAssets<T extends Asset>(balances: Array<T>, prices: Record<Address, bigint>, tokens: Record<Address, TokenData>): T[];
126
- static assetComparator<T extends Asset>(t1: T, t2: T, prices1: Record<Address, bigint> | undefined, prices2: Record<Address, bigint> | undefined, tokens1: Record<Address, TokenData> | undefined, tokens2: Record<Address, TokenData> | undefined): 1 | 0 | -1;
127
- static tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | 0 | -1;
126
+ static assetComparator<T extends Asset>(t1: T, t2: T, prices1: Record<Address, bigint> | undefined, prices2: Record<Address, bigint> | undefined, tokens1: Record<Address, TokenData> | undefined, tokens2: Record<Address, TokenData> | undefined): 1 | -1 | 0;
127
+ static tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | -1 | 0;
128
128
  static amountAbcComparator(t1: bigint, t2: bigint): 1 | -1;
129
129
  isForbidden(token: Address): boolean;
130
130
  isQuoted(token: Address): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "12.0.0-next.7",
3
+ "version": "12.0.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -51,24 +51,24 @@
51
51
  "typecheck:ci": "tsc --noEmit"
52
52
  },
53
53
  "dependencies": {
54
- "@gearbox-protocol/integrations-v3": "1.52.1",
54
+ "@gearbox-protocol/integrations-v3": "1.52.2",
55
55
  "@redstone-finance/evm-connector": "^0.9.0",
56
56
  "@redstone-finance/protocol": "^0.9.0",
57
57
  "@redstone-finance/sdk": "^0.9.0",
58
58
  "@types/bn.js": "^5.2.0",
59
- "abitype": "^1.2.2",
59
+ "abitype": "^1.2.3",
60
60
  "bn.js": "^5.2.2",
61
61
  "buffer": "^6.0.3",
62
62
  "date-fns": "^4.1.0",
63
63
  "decimal.js-light": "^2.5.1",
64
64
  "viem": ">=2.23.15 <3.0.0",
65
- "zod": "^4.1.13"
65
+ "zod": "^4.2.1"
66
66
  },
67
67
  "devDependencies": {
68
- "@biomejs/biome": "^2.3.8",
68
+ "@biomejs/biome": "^2.3.10",
69
69
  "@commitlint/cli": "^20.2.0",
70
70
  "@commitlint/config-conventional": "^20.2.0",
71
- "@gearbox-protocol/biome-config": "^1.0.14",
71
+ "@gearbox-protocol/biome-config": "^1.0.16",
72
72
  "@types/cross-spawn": "^6.0.6",
73
73
  "axios": "^1.13.2",
74
74
  "cross-spawn": "^7.0.6",
@@ -80,7 +80,7 @@
80
80
  "tsx": "^4.21.0",
81
81
  "typescript": "^5.9.3",
82
82
  "viem-deal": "^2.0.4",
83
- "vitest": "^4.0.15"
83
+ "vitest": "^4.0.16"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "axios": "^1.0.0",