@gearbox-protocol/sdk 11.12.0 → 11.12.2

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.
@@ -22,6 +22,28 @@ __export(IWithdrawalCompressorV310_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(IWithdrawalCompressorV310_exports);
24
24
  const iWithdrawalCompressorV310Abi = [
25
+ {
26
+ type: "constructor",
27
+ inputs: [
28
+ { name: "_owner", internalType: "address", type: "address" },
29
+ { name: "addressProvider_", internalType: "address", type: "address" }
30
+ ],
31
+ stateMutability: "nonpayable"
32
+ },
33
+ {
34
+ type: "function",
35
+ inputs: [],
36
+ name: "addressProvider",
37
+ outputs: [{ name: "", internalType: "address", type: "address" }],
38
+ stateMutability: "view"
39
+ },
40
+ {
41
+ type: "function",
42
+ inputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
43
+ name: "compressorTypeToCompressor",
44
+ outputs: [{ name: "", internalType: "address", type: "address" }],
45
+ stateMutability: "view"
46
+ },
25
47
  {
26
48
  type: "function",
27
49
  inputs: [],
@@ -139,7 +161,7 @@ const iWithdrawalCompressorV310Abi = [
139
161
  name: "getWithdrawalRequestResult",
140
162
  outputs: [
141
163
  {
142
- name: "",
164
+ name: "withdrawal",
143
165
  internalType: "struct RequestableWithdrawal",
144
166
  type: "tuple",
145
167
  components: [
@@ -170,12 +192,121 @@ const iWithdrawalCompressorV310Abi = [
170
192
  ],
171
193
  stateMutability: "view"
172
194
  },
195
+ // TODO: REMOVE COMMENTS AFTER MIGRATION TO MULTIPLE
196
+ // {
197
+ // type: "function",
198
+ // inputs: [
199
+ // { name: "creditAccount", internalType: "address", type: "address" },
200
+ // { name: "token", internalType: "address", type: "address" },
201
+ // { name: "withdrawalToken", internalType: "address", type: "address" },
202
+ // { name: "amount", internalType: "uint256", type: "uint256" },
203
+ // ],
204
+ // name: "getWithdrawalRequestResult",
205
+ // outputs: [
206
+ // {
207
+ // name: "withdrawal",
208
+ // internalType: "struct RequestableWithdrawal",
209
+ // type: "tuple",
210
+ // components: [
211
+ // { name: "token", internalType: "address", type: "address" },
212
+ // { name: "amountIn", internalType: "uint256", type: "uint256" },
213
+ // {
214
+ // name: "outputs",
215
+ // internalType: "struct WithdrawalOutput[]",
216
+ // type: "tuple[]",
217
+ // components: [
218
+ // { name: "token", internalType: "address", type: "address" },
219
+ // { name: "isDelayed", internalType: "bool", type: "bool" },
220
+ // { name: "amount", internalType: "uint256", type: "uint256" },
221
+ // ],
222
+ // },
223
+ // {
224
+ // name: "requestCalls",
225
+ // internalType: "struct MultiCall[]",
226
+ // type: "tuple[]",
227
+ // components: [
228
+ // { name: "target", internalType: "address", type: "address" },
229
+ // { name: "callData", internalType: "bytes", type: "bytes" },
230
+ // ],
231
+ // },
232
+ // { name: "claimableAt", internalType: "uint256", type: "uint256" },
233
+ // ],
234
+ // },
235
+ // ],
236
+ // stateMutability: "view",
237
+ // },
238
+ {
239
+ type: "function",
240
+ inputs: [],
241
+ name: "owner",
242
+ outputs: [{ name: "", internalType: "address", type: "address" }],
243
+ stateMutability: "view"
244
+ },
245
+ {
246
+ type: "function",
247
+ inputs: [],
248
+ name: "renounceOwnership",
249
+ outputs: [],
250
+ stateMutability: "nonpayable"
251
+ },
252
+ {
253
+ type: "function",
254
+ inputs: [
255
+ { name: "subcompressor", internalType: "address", type: "address" }
256
+ ],
257
+ name: "setSubcompressor",
258
+ outputs: [],
259
+ stateMutability: "nonpayable"
260
+ },
261
+ {
262
+ type: "function",
263
+ inputs: [
264
+ { name: "withdrawableType", internalType: "bytes32", type: "bytes32" },
265
+ { name: "compressorType", internalType: "bytes32", type: "bytes32" }
266
+ ],
267
+ name: "setWithdrawableTypeToCompressorType",
268
+ outputs: [],
269
+ stateMutability: "nonpayable"
270
+ },
271
+ {
272
+ type: "function",
273
+ inputs: [{ name: "newOwner", internalType: "address", type: "address" }],
274
+ name: "transferOwnership",
275
+ outputs: [],
276
+ stateMutability: "nonpayable"
277
+ },
173
278
  {
174
279
  type: "function",
175
280
  inputs: [],
176
281
  name: "version",
177
282
  outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
178
283
  stateMutability: "view"
284
+ },
285
+ {
286
+ type: "function",
287
+ inputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
288
+ name: "withdrawableTypeToCompressorType",
289
+ outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
290
+ stateMutability: "view"
291
+ },
292
+ {
293
+ type: "event",
294
+ anonymous: false,
295
+ inputs: [
296
+ {
297
+ name: "previousOwner",
298
+ internalType: "address",
299
+ type: "address",
300
+ indexed: true
301
+ },
302
+ {
303
+ name: "newOwner",
304
+ internalType: "address",
305
+ type: "address",
306
+ indexed: true
307
+ }
308
+ ],
309
+ name: "OwnershipTransferred"
179
310
  }
180
311
  ];
181
312
  // Annotate the CommonJS export names for ESM import in node:
@@ -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
  });
@@ -36,9 +36,8 @@ var import_router = require("../router/index.js");
36
36
  var import_sdk_legacy = require("../sdk-legacy/index.js");
37
37
  var import_utils = require("../utils/index.js");
38
38
  var import_viem2 = require("../utils/viem/index.js");
39
- function getWithdrawalCompressorAddress(chainId) {
40
- const compressor = chainId === 1 ? "0xfB79b6713fe214B8748ED7b0db1f93E4f1aC9d29" : void 0;
41
- return compressor;
39
+ function getWithdrawalCompressorAddress(_chainId) {
40
+ return "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023";
42
41
  }
43
42
  class AbstractCreditAccountService extends import_base.SDKConstruct {
44
43
  #compressor;
@@ -205,12 +204,12 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
205
204
  }
206
205
  /**
207
206
  * Method to get all connected bots for credit account
208
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
207
+ * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
209
208
  and their credit managers to check connected bots on
210
209
  * @returns call result of getConnectedBots for each credit account
211
210
  */
212
- async getConnectedBots(accountsToCheck, legacyMigrationBot) {
213
- const [resp, migration] = await Promise.all([
211
+ async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
212
+ const [resp, migration, additional] = await Promise.all([
214
213
  this.client.multicall({
215
214
  contracts: accountsToCheck.map((o) => {
216
215
  const pool = this.sdk.marketRegister.findByCreditManager(
@@ -225,12 +224,41 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
225
224
  }),
226
225
  allowFailure: true
227
226
  }),
228
- this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot)
227
+ this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot),
228
+ this.getActiveBots(accountsToCheck, additionalBots)
229
229
  ]);
230
- return { legacy: resp, legacyMigration: migration };
230
+ return {
231
+ legacy: resp,
232
+ additionalBots: additional,
233
+ legacyMigration: migration
234
+ };
235
+ }
236
+ async getActiveBots(accountsToCheck, bots) {
237
+ const result = await this.client.multicall({
238
+ contracts: accountsToCheck.flatMap((ca) => {
239
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
240
+ return bots.map((bot) => {
241
+ return {
242
+ abi: (0, import_constants.isV300)(cm.creditFacade.version) ? import_v300.iBotListV300Abi : import_generated.iBotListV310Abi,
243
+ address: cm.creditFacade.botList,
244
+ functionName: "getBotStatus",
245
+ args: (0, import_constants.isV300)(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
246
+ };
247
+ });
248
+ }),
249
+ allowFailure: true
250
+ });
251
+ const botsByCAIndex = accountsToCheck.reduce((acc, _, index) => {
252
+ const r = result.slice(index * bots.length, (index + 1) * bots.length);
253
+ acc.push({
254
+ result: r
255
+ });
256
+ return acc;
257
+ }, []);
258
+ return botsByCAIndex;
231
259
  }
232
- async getActiveMigrationBots(accountsToCheck, legacyMigrationBot) {
233
- if (legacyMigrationBot) {
260
+ async getActiveMigrationBots(accountsToCheck, bot) {
261
+ if (bot) {
234
262
  const result = await this.client.multicall({
235
263
  contracts: accountsToCheck.map((ca) => {
236
264
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -240,12 +268,12 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
240
268
  abi: (0, import_constants.isV300)(cm.creditFacade.version) ? import_v300.iBotListV300Abi : import_generated.iBotListV310Abi,
241
269
  address: cm.creditFacade.botList,
242
270
  functionName: "getBotStatus",
243
- args: (0, import_constants.isV300)(cm.creditFacade.version) ? [legacyMigrationBot, ca.creditManager, ca.creditAccount] : [legacyMigrationBot, ca.creditAccount]
271
+ args: (0, import_constants.isV300)(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
244
272
  };
245
273
  }),
246
274
  allowFailure: true
247
275
  });
248
- return { result, botAddress: legacyMigrationBot };
276
+ return { result, botAddress: bot };
249
277
  }
250
278
  return void 0;
251
279
  }
@@ -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)({
@@ -1,4 +1,26 @@
1
1
  const iWithdrawalCompressorV310Abi = [
2
+ {
3
+ type: "constructor",
4
+ inputs: [
5
+ { name: "_owner", internalType: "address", type: "address" },
6
+ { name: "addressProvider_", internalType: "address", type: "address" }
7
+ ],
8
+ stateMutability: "nonpayable"
9
+ },
10
+ {
11
+ type: "function",
12
+ inputs: [],
13
+ name: "addressProvider",
14
+ outputs: [{ name: "", internalType: "address", type: "address" }],
15
+ stateMutability: "view"
16
+ },
17
+ {
18
+ type: "function",
19
+ inputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
20
+ name: "compressorTypeToCompressor",
21
+ outputs: [{ name: "", internalType: "address", type: "address" }],
22
+ stateMutability: "view"
23
+ },
2
24
  {
3
25
  type: "function",
4
26
  inputs: [],
@@ -116,7 +138,7 @@ const iWithdrawalCompressorV310Abi = [
116
138
  name: "getWithdrawalRequestResult",
117
139
  outputs: [
118
140
  {
119
- name: "",
141
+ name: "withdrawal",
120
142
  internalType: "struct RequestableWithdrawal",
121
143
  type: "tuple",
122
144
  components: [
@@ -147,12 +169,121 @@ const iWithdrawalCompressorV310Abi = [
147
169
  ],
148
170
  stateMutability: "view"
149
171
  },
172
+ // TODO: REMOVE COMMENTS AFTER MIGRATION TO MULTIPLE
173
+ // {
174
+ // type: "function",
175
+ // inputs: [
176
+ // { name: "creditAccount", internalType: "address", type: "address" },
177
+ // { name: "token", internalType: "address", type: "address" },
178
+ // { name: "withdrawalToken", internalType: "address", type: "address" },
179
+ // { name: "amount", internalType: "uint256", type: "uint256" },
180
+ // ],
181
+ // name: "getWithdrawalRequestResult",
182
+ // outputs: [
183
+ // {
184
+ // name: "withdrawal",
185
+ // internalType: "struct RequestableWithdrawal",
186
+ // type: "tuple",
187
+ // components: [
188
+ // { name: "token", internalType: "address", type: "address" },
189
+ // { name: "amountIn", internalType: "uint256", type: "uint256" },
190
+ // {
191
+ // name: "outputs",
192
+ // internalType: "struct WithdrawalOutput[]",
193
+ // type: "tuple[]",
194
+ // components: [
195
+ // { name: "token", internalType: "address", type: "address" },
196
+ // { name: "isDelayed", internalType: "bool", type: "bool" },
197
+ // { name: "amount", internalType: "uint256", type: "uint256" },
198
+ // ],
199
+ // },
200
+ // {
201
+ // name: "requestCalls",
202
+ // internalType: "struct MultiCall[]",
203
+ // type: "tuple[]",
204
+ // components: [
205
+ // { name: "target", internalType: "address", type: "address" },
206
+ // { name: "callData", internalType: "bytes", type: "bytes" },
207
+ // ],
208
+ // },
209
+ // { name: "claimableAt", internalType: "uint256", type: "uint256" },
210
+ // ],
211
+ // },
212
+ // ],
213
+ // stateMutability: "view",
214
+ // },
215
+ {
216
+ type: "function",
217
+ inputs: [],
218
+ name: "owner",
219
+ outputs: [{ name: "", internalType: "address", type: "address" }],
220
+ stateMutability: "view"
221
+ },
222
+ {
223
+ type: "function",
224
+ inputs: [],
225
+ name: "renounceOwnership",
226
+ outputs: [],
227
+ stateMutability: "nonpayable"
228
+ },
229
+ {
230
+ type: "function",
231
+ inputs: [
232
+ { name: "subcompressor", internalType: "address", type: "address" }
233
+ ],
234
+ name: "setSubcompressor",
235
+ outputs: [],
236
+ stateMutability: "nonpayable"
237
+ },
238
+ {
239
+ type: "function",
240
+ inputs: [
241
+ { name: "withdrawableType", internalType: "bytes32", type: "bytes32" },
242
+ { name: "compressorType", internalType: "bytes32", type: "bytes32" }
243
+ ],
244
+ name: "setWithdrawableTypeToCompressorType",
245
+ outputs: [],
246
+ stateMutability: "nonpayable"
247
+ },
248
+ {
249
+ type: "function",
250
+ inputs: [{ name: "newOwner", internalType: "address", type: "address" }],
251
+ name: "transferOwnership",
252
+ outputs: [],
253
+ stateMutability: "nonpayable"
254
+ },
150
255
  {
151
256
  type: "function",
152
257
  inputs: [],
153
258
  name: "version",
154
259
  outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
155
260
  stateMutability: "view"
261
+ },
262
+ {
263
+ type: "function",
264
+ inputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
265
+ name: "withdrawableTypeToCompressorType",
266
+ outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
267
+ stateMutability: "view"
268
+ },
269
+ {
270
+ type: "event",
271
+ anonymous: false,
272
+ inputs: [
273
+ {
274
+ name: "previousOwner",
275
+ internalType: "address",
276
+ type: "address",
277
+ indexed: true
278
+ },
279
+ {
280
+ name: "newOwner",
281
+ internalType: "address",
282
+ type: "address",
283
+ indexed: true
284
+ }
285
+ ],
286
+ name: "OwnershipTransferred"
156
287
  }
157
288
  ];
158
289
  export {
@@ -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
  };
@@ -26,9 +26,8 @@ import { assetsMap } from "../router/index.js";
26
26
  import { BigIntMath } from "../sdk-legacy/index.js";
27
27
  import { AddressMap, childLogger } from "../utils/index.js";
28
28
  import { simulateWithPriceUpdates } from "../utils/viem/index.js";
29
- function getWithdrawalCompressorAddress(chainId) {
30
- const compressor = chainId === 1 ? "0xfB79b6713fe214B8748ED7b0db1f93E4f1aC9d29" : void 0;
31
- return compressor;
29
+ function getWithdrawalCompressorAddress(_chainId) {
30
+ return "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023";
32
31
  }
33
32
  class AbstractCreditAccountService extends SDKConstruct {
34
33
  #compressor;
@@ -195,12 +194,12 @@ class AbstractCreditAccountService extends SDKConstruct {
195
194
  }
196
195
  /**
197
196
  * Method to get all connected bots for credit account
198
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
197
+ * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
199
198
  and their credit managers to check connected bots on
200
199
  * @returns call result of getConnectedBots for each credit account
201
200
  */
202
- async getConnectedBots(accountsToCheck, legacyMigrationBot) {
203
- const [resp, migration] = await Promise.all([
201
+ async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
202
+ const [resp, migration, additional] = await Promise.all([
204
203
  this.client.multicall({
205
204
  contracts: accountsToCheck.map((o) => {
206
205
  const pool = this.sdk.marketRegister.findByCreditManager(
@@ -215,12 +214,41 @@ class AbstractCreditAccountService extends SDKConstruct {
215
214
  }),
216
215
  allowFailure: true
217
216
  }),
218
- this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot)
217
+ this.getActiveMigrationBots(accountsToCheck, legacyMigrationBot),
218
+ this.getActiveBots(accountsToCheck, additionalBots)
219
219
  ]);
220
- return { legacy: resp, legacyMigration: migration };
220
+ return {
221
+ legacy: resp,
222
+ additionalBots: additional,
223
+ legacyMigration: migration
224
+ };
225
+ }
226
+ async getActiveBots(accountsToCheck, bots) {
227
+ const result = await this.client.multicall({
228
+ contracts: accountsToCheck.flatMap((ca) => {
229
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
230
+ return bots.map((bot) => {
231
+ return {
232
+ abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
233
+ address: cm.creditFacade.botList,
234
+ functionName: "getBotStatus",
235
+ args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
236
+ };
237
+ });
238
+ }),
239
+ allowFailure: true
240
+ });
241
+ const botsByCAIndex = accountsToCheck.reduce((acc, _, index) => {
242
+ const r = result.slice(index * bots.length, (index + 1) * bots.length);
243
+ acc.push({
244
+ result: r
245
+ });
246
+ return acc;
247
+ }, []);
248
+ return botsByCAIndex;
221
249
  }
222
- async getActiveMigrationBots(accountsToCheck, legacyMigrationBot) {
223
- if (legacyMigrationBot) {
250
+ async getActiveMigrationBots(accountsToCheck, bot) {
251
+ if (bot) {
224
252
  const result = await this.client.multicall({
225
253
  contracts: accountsToCheck.map((ca) => {
226
254
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -230,12 +258,12 @@ class AbstractCreditAccountService extends SDKConstruct {
230
258
  abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
231
259
  address: cm.creditFacade.botList,
232
260
  functionName: "getBotStatus",
233
- args: isV300(cm.creditFacade.version) ? [legacyMigrationBot, ca.creditManager, ca.creditAccount] : [legacyMigrationBot, ca.creditAccount]
261
+ args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
234
262
  };
235
263
  }),
236
264
  allowFailure: true
237
265
  });
238
- return { result, botAddress: legacyMigrationBot };
266
+ return { result, botAddress: bot };
239
267
  }
240
268
  return void 0;
241
269
  }
@@ -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({
@@ -1,4 +1,40 @@
1
1
  export declare const iWithdrawalCompressorV310Abi: readonly [{
2
+ readonly type: "constructor";
3
+ readonly inputs: readonly [{
4
+ readonly name: "_owner";
5
+ readonly internalType: "address";
6
+ readonly type: "address";
7
+ }, {
8
+ readonly name: "addressProvider_";
9
+ readonly internalType: "address";
10
+ readonly type: "address";
11
+ }];
12
+ readonly stateMutability: "nonpayable";
13
+ }, {
14
+ readonly type: "function";
15
+ readonly inputs: readonly [];
16
+ readonly name: "addressProvider";
17
+ readonly outputs: readonly [{
18
+ readonly name: "";
19
+ readonly internalType: "address";
20
+ readonly type: "address";
21
+ }];
22
+ readonly stateMutability: "view";
23
+ }, {
24
+ readonly type: "function";
25
+ readonly inputs: readonly [{
26
+ readonly name: "";
27
+ readonly internalType: "bytes32";
28
+ readonly type: "bytes32";
29
+ }];
30
+ readonly name: "compressorTypeToCompressor";
31
+ readonly outputs: readonly [{
32
+ readonly name: "";
33
+ readonly internalType: "address";
34
+ readonly type: "address";
35
+ }];
36
+ readonly stateMutability: "view";
37
+ }, {
2
38
  readonly type: "function";
3
39
  readonly inputs: readonly [];
4
40
  readonly name: "contractType";
@@ -147,7 +183,7 @@ export declare const iWithdrawalCompressorV310Abi: readonly [{
147
183
  }];
148
184
  readonly name: "getWithdrawalRequestResult";
149
185
  readonly outputs: readonly [{
150
- readonly name: "";
186
+ readonly name: "withdrawal";
151
187
  readonly internalType: "struct RequestableWithdrawal";
152
188
  readonly type: "tuple";
153
189
  readonly components: readonly [{
@@ -195,6 +231,56 @@ export declare const iWithdrawalCompressorV310Abi: readonly [{
195
231
  }];
196
232
  }];
197
233
  readonly stateMutability: "view";
234
+ }, {
235
+ readonly type: "function";
236
+ readonly inputs: readonly [];
237
+ readonly name: "owner";
238
+ readonly outputs: readonly [{
239
+ readonly name: "";
240
+ readonly internalType: "address";
241
+ readonly type: "address";
242
+ }];
243
+ readonly stateMutability: "view";
244
+ }, {
245
+ readonly type: "function";
246
+ readonly inputs: readonly [];
247
+ readonly name: "renounceOwnership";
248
+ readonly outputs: readonly [];
249
+ readonly stateMutability: "nonpayable";
250
+ }, {
251
+ readonly type: "function";
252
+ readonly inputs: readonly [{
253
+ readonly name: "subcompressor";
254
+ readonly internalType: "address";
255
+ readonly type: "address";
256
+ }];
257
+ readonly name: "setSubcompressor";
258
+ readonly outputs: readonly [];
259
+ readonly stateMutability: "nonpayable";
260
+ }, {
261
+ readonly type: "function";
262
+ readonly inputs: readonly [{
263
+ readonly name: "withdrawableType";
264
+ readonly internalType: "bytes32";
265
+ readonly type: "bytes32";
266
+ }, {
267
+ readonly name: "compressorType";
268
+ readonly internalType: "bytes32";
269
+ readonly type: "bytes32";
270
+ }];
271
+ readonly name: "setWithdrawableTypeToCompressorType";
272
+ readonly outputs: readonly [];
273
+ readonly stateMutability: "nonpayable";
274
+ }, {
275
+ readonly type: "function";
276
+ readonly inputs: readonly [{
277
+ readonly name: "newOwner";
278
+ readonly internalType: "address";
279
+ readonly type: "address";
280
+ }];
281
+ readonly name: "transferOwnership";
282
+ readonly outputs: readonly [];
283
+ readonly stateMutability: "nonpayable";
198
284
  }, {
199
285
  readonly type: "function";
200
286
  readonly inputs: readonly [];
@@ -205,4 +291,33 @@ export declare const iWithdrawalCompressorV310Abi: readonly [{
205
291
  readonly type: "uint256";
206
292
  }];
207
293
  readonly stateMutability: "view";
294
+ }, {
295
+ readonly type: "function";
296
+ readonly inputs: readonly [{
297
+ readonly name: "";
298
+ readonly internalType: "bytes32";
299
+ readonly type: "bytes32";
300
+ }];
301
+ readonly name: "withdrawableTypeToCompressorType";
302
+ readonly outputs: readonly [{
303
+ readonly name: "";
304
+ readonly internalType: "bytes32";
305
+ readonly type: "bytes32";
306
+ }];
307
+ readonly stateMutability: "view";
308
+ }, {
309
+ readonly type: "event";
310
+ readonly anonymous: false;
311
+ readonly inputs: readonly [{
312
+ readonly name: "previousOwner";
313
+ readonly internalType: "address";
314
+ readonly type: "address";
315
+ readonly indexed: true;
316
+ }, {
317
+ readonly name: "newOwner";
318
+ readonly internalType: "address";
319
+ readonly type: "address";
320
+ readonly indexed: true;
321
+ }];
322
+ readonly name: "OwnershipTransferred";
208
323
  }];
@@ -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,11 +5,11 @@ 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
  }
12
- export declare function getWithdrawalCompressorAddress(chainId: number): "0xfB79b6713fe214B8748ED7b0db1f93E4f1aC9d29" | undefined;
12
+ export declare function getWithdrawalCompressorAddress(_chainId: number): "0x36F3d0Bb73CBC2E94fE24dF0f26a689409cF9023";
13
13
  export declare abstract class AbstractCreditAccountService extends SDKConstruct {
14
14
  #private;
15
15
  constructor(sdk: GearboxSDK, options?: CreditAccountServiceOptions);
@@ -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.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",