@gearbox-protocol/sdk 8.26.6 → 8.27.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.
Files changed (40) hide show
  1. package/dist/cjs/plugins/bots/BotsPlugin.js +1 -1
  2. package/dist/cjs/plugins/bots/types.js +3 -3
  3. package/dist/cjs/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +202 -0
  4. package/dist/cjs/sdk/accountMigration/MigrateCreditAccountsServiceV300.js +30 -0
  5. package/dist/cjs/sdk/accountMigration/MigrateCreditAccountsServiceV310.js +30 -0
  6. package/dist/cjs/sdk/accountMigration/createMigrateCreditAccountsService.js +41 -0
  7. package/dist/cjs/sdk/accountMigration/index.js +26 -0
  8. package/dist/cjs/sdk/accountMigration/types.js +28 -0
  9. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +42 -14
  10. package/dist/cjs/sdk/accounts/constants.js +3 -0
  11. package/dist/cjs/sdk/index.js +2 -0
  12. package/dist/cjs/sdk/sdk-legacy/core/transactions.js +20 -0
  13. package/dist/esm/plugins/bots/BotsPlugin.js +2 -2
  14. package/dist/esm/plugins/bots/types.js +2 -2
  15. package/dist/esm/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +181 -0
  16. package/dist/esm/sdk/accountMigration/MigrateCreditAccountsServiceV300.js +6 -0
  17. package/dist/esm/sdk/accountMigration/MigrateCreditAccountsServiceV310.js +6 -0
  18. package/dist/esm/sdk/accountMigration/createMigrateCreditAccountsService.js +17 -0
  19. package/dist/esm/sdk/accountMigration/index.js +3 -0
  20. package/dist/esm/sdk/accountMigration/types.js +4 -0
  21. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +47 -15
  22. package/dist/esm/sdk/accounts/constants.js +3 -0
  23. package/dist/esm/sdk/index.js +1 -0
  24. package/dist/esm/sdk/sdk-legacy/core/transactions.js +19 -0
  25. package/dist/types/plugins/bots/PartialLiquidationBotV300Contract.d.ts +3 -3
  26. package/dist/types/plugins/bots/types.d.ts +3 -3
  27. package/dist/types/sdk/accountMigration/AbstractMigrateCreditAccountsService.d.ts +39 -0
  28. package/dist/types/sdk/accountMigration/MigrateCreditAccountsServiceV300.d.ts +4 -0
  29. package/dist/types/sdk/accountMigration/MigrateCreditAccountsServiceV310.d.ts +4 -0
  30. package/dist/types/sdk/accountMigration/createMigrateCreditAccountsService.d.ts +8 -0
  31. package/dist/types/sdk/accountMigration/index.d.ts +3 -0
  32. package/dist/types/sdk/accountMigration/types.d.ts +74 -0
  33. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +9 -5
  34. package/dist/types/sdk/accounts/types.d.ts +37 -9
  35. package/dist/types/sdk/index.d.ts +1 -0
  36. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +2 -2
  37. package/dist/types/sdk/market/oracle/types.d.ts +2 -2
  38. package/dist/types/sdk/sdk-legacy/core/creditAccount.d.ts +2 -2
  39. package/dist/types/sdk/sdk-legacy/core/transactions.d.ts +13 -1
  40. package/package.json +1 -1
@@ -79,7 +79,7 @@ class BotsPlugin extends import_sdk.BasePlugin {
79
79
  throw new Error(`expected 4 bots v300 for market configurator ${mc}`);
80
80
  }
81
81
  for (let i = 0; i < bots.length; i++) {
82
- bots[i].botType = import_types.BOT_TYPES[i];
82
+ bots[i].botType = import_types.LIQUIDATION_BOT_TYPES[i];
83
83
  }
84
84
  }
85
85
  this.botsByMarket.upsert(mc, bots);
@@ -18,10 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var types_exports = {};
20
20
  __export(types_exports, {
21
- BOT_TYPES: () => BOT_TYPES
21
+ LIQUIDATION_BOT_TYPES: () => LIQUIDATION_BOT_TYPES
22
22
  });
23
23
  module.exports = __toCommonJS(types_exports);
24
- const BOT_TYPES = [
24
+ const LIQUIDATION_BOT_TYPES = [
25
25
  "PARTIAL_LIQUIDATION_BOT",
26
26
  "DELEVERAGE_BOT_PEGGED",
27
27
  "DELEVERAGE_BOT_LV",
@@ -29,5 +29,5 @@ const BOT_TYPES = [
29
29
  ];
30
30
  // Annotate the CommonJS export names for ESM import in node:
31
31
  0 && (module.exports = {
32
- BOT_TYPES
32
+ LIQUIDATION_BOT_TYPES
33
33
  });
@@ -0,0 +1,202 @@
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 AbstractMigrateCreditAccountsService_exports = {};
20
+ __export(AbstractMigrateCreditAccountsService_exports, {
21
+ AbstractMigrateCreditAccountsService: () => AbstractMigrateCreditAccountsService
22
+ });
23
+ module.exports = __toCommonJS(AbstractMigrateCreditAccountsService_exports);
24
+ var import_viem = require("viem");
25
+ var import_migration = require("../../abi/migration.js");
26
+ var import_createCreditAccountService = require("../accounts/createCreditAccountService.js");
27
+ var import_base = require("../base/index.js");
28
+ var import_chains = require("../chain/chains.js");
29
+ var import_versions = require("../constants/versions.js");
30
+ var import_utils = require("../utils/index.js");
31
+ class AbstractMigrateCreditAccountsService extends import_base.SDKConstruct {
32
+ #logger;
33
+ #version;
34
+ #service;
35
+ // TODO: any better way to handle this?
36
+ static V300_TO_V310_TOKENS_OVERRIDES = {
37
+ [import_chains.chains.Mainnet.id]: {
38
+ // stkcvxRLUSD_USDC
39
+ ["0x444FA0ffb033265591895b66c81c2e5fF606E097".toLowerCase()]: "0x87FA6c0296c986D1C901d72571282D57916B964a".toLowerCase(),
40
+ // stkcvxllamathena
41
+ ["0x72eD19788Bce2971A5ed6401662230ee57e254B7".toLowerCase()]: "0xB5528130B1d5D24aD172bF54CeeD062232AfbFBe".toLowerCase(),
42
+ // stkUSDS
43
+ ["0xcB5D10A57Aeb622b92784D53F730eE2210ab370E".toLowerCase()]: "0x00F7C0d39B05089e93858A82439EA17dE7160B5a".toLowerCase()
44
+ }
45
+ };
46
+ static accountMigratorBot = "0x286Fe53994f5668D56538Aa10eaa3Ac36f878e9C".toLowerCase();
47
+ // "0xc19ddEbDEB7Ba119eB9F23d079dcEaBC1B25B41f".toLowerCase() as Address;
48
+ static accountMigratorPreviewer = "0x5514de935f39AB0a137b4A1c984c872513C02f29".toLowerCase();
49
+ // "0xe6d2A2477722Af204899cfd3257A43aDAE1Ea264".toLowerCase() as Address;
50
+ // 0x99B63E7030e6f066731CF4e166e87D1D18e98B45.toLowerCase() as Address;
51
+ constructor(sdk, version) {
52
+ super(sdk);
53
+ this.#version = version;
54
+ this.#service = (0, import_createCreditAccountService.createCreditAccountService)(this.sdk, version);
55
+ this.#logger = (0, import_utils.childLogger)("CreditAccountsService", sdk.logger);
56
+ this.#logger?.debug(
57
+ `Created MigrateCreditAccountsService with version: ${this.#version}`
58
+ );
59
+ }
60
+ /**
61
+ * Preview delayed withdrawal for a given credit account
62
+ * @param props - {@link PreviewCreditAccountMigrationProps}
63
+ * @returns
64
+ */
65
+ async previewCreditAccountMigration({
66
+ previewerAddress,
67
+ creditAccount,
68
+ targetCreditManager,
69
+ expectedTargetQuota
70
+ }) {
71
+ const updates = await this.getPriceUpdatesForMigration(
72
+ targetCreditManager,
73
+ expectedTargetQuota
74
+ );
75
+ const contract = (0, import_viem.getContract)({
76
+ address: previewerAddress,
77
+ abi: import_migration.accountMigratorPreviewerV310Abi,
78
+ client: {
79
+ public: this.sdk.provider.publicClient
80
+ }
81
+ });
82
+ const { result } = await contract.simulate.previewMigration([
83
+ creditAccount.creditAccount,
84
+ targetCreditManager,
85
+ updates
86
+ ]);
87
+ return result;
88
+ }
89
+ /**
90
+ * Migrates credit account with a given preview result
91
+ * @param props - {@link MigrateCreditAccountProps}
92
+ * @returns
93
+ */
94
+ async migrateCreditAccount({
95
+ accountMigratorBot,
96
+ targetCreditManager,
97
+ signer,
98
+ preview,
99
+ expectedTargetQuota,
100
+ account
101
+ }) {
102
+ const updates = await this.getPriceUpdatesForMigration(
103
+ targetCreditManager,
104
+ expectedTargetQuota
105
+ );
106
+ const contract = (0, import_viem.getContract)({
107
+ address: accountMigratorBot,
108
+ abi: import_migration.accountMigratorBotV310Abi,
109
+ client: signer
110
+ });
111
+ const tx = await contract.write.migrateCreditAccount(
112
+ [preview.migrationParams, updates],
113
+ { account, chain: signer.chain }
114
+ );
115
+ return tx;
116
+ }
117
+ async getPriceUpdatesForMigration(targetCreditManager, expectedTargetQuota) {
118
+ const updatesPayload = await this.#service.getOnDemandPriceUpdates(
119
+ targetCreditManager,
120
+ void 0,
121
+ expectedTargetQuota
122
+ );
123
+ const market = this.sdk.marketRegister.findByCreditManager(targetCreditManager);
124
+ const updates = updatesPayload.raw.length === 0 ? updatesPayload.raw : "priceFeed" in updatesPayload.raw[0] ? updatesPayload.raw : void 0;
125
+ if (!(0, import_versions.isV310)(market.priceOracle.version) || !updates)
126
+ throw new Error("Unsupported Price Feed");
127
+ return updates;
128
+ }
129
+ static getV310TargetTokenAddress(source, chainId) {
130
+ return AbstractMigrateCreditAccountsService.V300_TO_V310_TOKENS_OVERRIDES[chainId][source] ?? source;
131
+ }
132
+ static getMigrationBotAddress(chainId) {
133
+ const botAddress = chainId === import_chains.chains.Mainnet.id ? AbstractMigrateCreditAccountsService.accountMigratorBot : void 0;
134
+ const previewerAddress = chainId === import_chains.chains.Mainnet.id ? AbstractMigrateCreditAccountsService.accountMigratorPreviewer : void 0;
135
+ return previewerAddress && botAddress ? { botAddress, previewerAddress } : void 0;
136
+ }
137
+ static getMigrationBotData(chainId) {
138
+ const { botAddress } = AbstractMigrateCreditAccountsService.getMigrationBotAddress(chainId) || {};
139
+ return botAddress ? {
140
+ baseParams: {
141
+ addr: botAddress,
142
+ version: 310
143
+ },
144
+ address: botAddress,
145
+ version: 310,
146
+ botType: "MIGRATION_BOT"
147
+ } : void 0;
148
+ }
149
+ static getTokensToMigrate(creditAccount) {
150
+ const sourceTokensToMigrate = Object.values(creditAccount.tokens).filter(
151
+ (t) => creditAccount.isTokenEnabled(t.token) && t.balance > 1n
152
+ );
153
+ const targetTokensToMigrate = AbstractMigrateCreditAccountsService.getTokensAfterMigration(
154
+ sourceTokensToMigrate,
155
+ creditAccount.chainId
156
+ );
157
+ return { sourceTokensToMigrate, targetTokensToMigrate };
158
+ }
159
+ static getTokensAfterMigration(balances, chainId) {
160
+ const list = Array.isArray(balances) ? balances : Object.values(balances);
161
+ const res = list.map((a) => ({
162
+ ...a,
163
+ token: AbstractMigrateCreditAccountsService.getV310TargetTokenAddress(
164
+ a.token,
165
+ chainId
166
+ )
167
+ }));
168
+ return res;
169
+ }
170
+ static checkSourceCreditManager(sourceCreditManager, migrationBot, sdk) {
171
+ const cmData = sdk.marketRegister.findCreditManager(sourceCreditManager);
172
+ const botLc = migrationBot.toLowerCase();
173
+ const adapter = cmData.creditManager.adapters.values().find((a) => {
174
+ return a.targetContract.toLowerCase() === botLc;
175
+ });
176
+ return !!adapter;
177
+ }
178
+ static isSourceMigratableToTargetCM(targetTokensToMigrate, source, target, delayedPhantoms) {
179
+ const debt = source.borrowedAmountPlusInterestAndFees;
180
+ if (debt > target.maxDebt || debt < target.minDebt) return false;
181
+ const sourceUnderlying = source.underlying;
182
+ if (!target.supportedTokens[sourceUnderlying]) return false;
183
+ const collateralsCheckPassed = targetTokensToMigrate.every((a) => {
184
+ const tokenToMigrate = AbstractMigrateCreditAccountsService.getV310TargetTokenAddress(
185
+ a.token,
186
+ target.chainId
187
+ );
188
+ if (tokenToMigrate === target.underlyingToken) return true;
189
+ const zeroLt = target.liquidationThresholds[a.token] === 0n;
190
+ const quotaNotActive = target.quotas[a.token]?.isActive === false;
191
+ const supportedToken = !!target.supportedTokens[a.token];
192
+ const forbidden = !!target.forbiddenTokens[a.token];
193
+ const cmCheckPassed = supportedToken && !zeroLt && !quotaNotActive && !forbidden && !delayedPhantoms[a.token];
194
+ return cmCheckPassed;
195
+ });
196
+ return collateralsCheckPassed;
197
+ }
198
+ }
199
+ // Annotate the CommonJS export names for ESM import in node:
200
+ 0 && (module.exports = {
201
+ AbstractMigrateCreditAccountsService
202
+ });
@@ -0,0 +1,30 @@
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 MigrateCreditAccountsServiceV300_exports = {};
20
+ __export(MigrateCreditAccountsServiceV300_exports, {
21
+ MigrateCreditAccountsServiceV300: () => MigrateCreditAccountsServiceV300
22
+ });
23
+ module.exports = __toCommonJS(MigrateCreditAccountsServiceV300_exports);
24
+ var import_AbstractMigrateCreditAccountsService = require("./AbstractMigrateCreditAccountsService.js");
25
+ class MigrateCreditAccountsServiceV300 extends import_AbstractMigrateCreditAccountsService.AbstractMigrateCreditAccountsService {
26
+ }
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ MigrateCreditAccountsServiceV300
30
+ });
@@ -0,0 +1,30 @@
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 MigrateCreditAccountsServiceV310_exports = {};
20
+ __export(MigrateCreditAccountsServiceV310_exports, {
21
+ MigrateCreditAccountsServiceV310: () => MigrateCreditAccountsServiceV310
22
+ });
23
+ module.exports = __toCommonJS(MigrateCreditAccountsServiceV310_exports);
24
+ var import_AbstractMigrateCreditAccountsService = require("./AbstractMigrateCreditAccountsService.js");
25
+ class MigrateCreditAccountsServiceV310 extends import_AbstractMigrateCreditAccountsService.AbstractMigrateCreditAccountsService {
26
+ }
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ MigrateCreditAccountsServiceV310
30
+ });
@@ -0,0 +1,41 @@
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 createMigrateCreditAccountsService_exports = {};
20
+ __export(createMigrateCreditAccountsService_exports, {
21
+ createMigrateCreditAccountsService: () => createMigrateCreditAccountsService
22
+ });
23
+ module.exports = __toCommonJS(createMigrateCreditAccountsService_exports);
24
+ var import_constants = require("../constants/index.js");
25
+ var import_MigrateCreditAccountsServiceV300 = require("./MigrateCreditAccountsServiceV300.js");
26
+ var import_MigrateCreditAccountsServiceV310 = require("./MigrateCreditAccountsServiceV310.js");
27
+ function createMigrateCreditAccountsService(sdk, version) {
28
+ if ((0, import_constants.isV300)(version)) {
29
+ return new import_MigrateCreditAccountsServiceV300.MigrateCreditAccountsServiceV300(sdk, version);
30
+ }
31
+ if ((0, import_constants.isV310)(version)) {
32
+ return new import_MigrateCreditAccountsServiceV310.MigrateCreditAccountsServiceV310(sdk, version);
33
+ }
34
+ throw new Error(
35
+ `Unsupported Migrate Credit Account Service version ${version}`
36
+ );
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ createMigrateCreditAccountsService
41
+ });
@@ -0,0 +1,26 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var accountMigration_exports = {};
17
+ module.exports = __toCommonJS(accountMigration_exports);
18
+ __reExport(accountMigration_exports, require("./AbstractMigrateCreditAccountsService.js"), module.exports);
19
+ __reExport(accountMigration_exports, require("./createMigrateCreditAccountsService.js"), module.exports);
20
+ __reExport(accountMigration_exports, require("./types.js"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("./AbstractMigrateCreditAccountsService.js"),
24
+ ...require("./createMigrateCreditAccountsService.js"),
25
+ ...require("./types.js")
26
+ });
@@ -0,0 +1,28 @@
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 types_exports = {};
20
+ __export(types_exports, {
21
+ MIGRATION_BOT_TYPES: () => MIGRATION_BOT_TYPES
22
+ });
23
+ module.exports = __toCommonJS(types_exports);
24
+ const MIGRATION_BOT_TYPES = ["MIGRATION_BOT"];
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ MIGRATION_BOT_TYPES
28
+ });
@@ -25,6 +25,8 @@ var import_viem = require("viem");
25
25
  var import_compressors = require("../../abi/compressors.js");
26
26
  var import_iBaseRewardPool = require("../../abi/iBaseRewardPool.js");
27
27
  var import_v300 = require("../../abi/v300.js");
28
+ var import_v310 = require("../../abi/v310.js");
29
+ var import_AbstractMigrateCreditAccountsService = require("../accountMigration/AbstractMigrateCreditAccountsService.js");
28
30
  var import_base = require("../base/index.js");
29
31
  var import_constants = require("../constants/index.js");
30
32
  var import_router = require("../router/index.js");
@@ -192,21 +194,47 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
192
194
  * @returns call result of getConnectedBots for each credit account
193
195
  */
194
196
  async getConnectedBots(accountsToCheck) {
195
- const resp = await this.provider.publicClient.multicall({
196
- contracts: accountsToCheck.map((o) => {
197
- const pool = this.sdk.marketRegister.findByCreditManager(
198
- o.creditManager
199
- );
200
- return {
201
- abi: import_compressors.iPeripheryCompressorAbi,
202
- address: this.peripheryCompressor,
203
- functionName: "getConnectedBots",
204
- args: [pool.configurator.address, o.creditAccount]
205
- };
197
+ const [resp, migration] = await Promise.all([
198
+ this.provider.publicClient.multicall({
199
+ contracts: accountsToCheck.map((o) => {
200
+ const pool = this.sdk.marketRegister.findByCreditManager(
201
+ o.creditManager
202
+ );
203
+ return {
204
+ abi: import_compressors.iPeripheryCompressorAbi,
205
+ address: this.peripheryCompressor,
206
+ functionName: "getConnectedBots",
207
+ args: [pool.configurator.address, o.creditAccount]
208
+ };
209
+ }),
210
+ allowFailure: true
206
211
  }),
207
- allowFailure: true
208
- });
209
- return resp;
212
+ this.getActiveMigrationBots(accountsToCheck)
213
+ ]);
214
+ return { legacy: resp, legacyMigration: migration };
215
+ }
216
+ async getActiveMigrationBots(accountsToCheck) {
217
+ const migrationBot = import_AbstractMigrateCreditAccountsService.AbstractMigrateCreditAccountsService.getMigrationBotAddress(
218
+ this.sdk.provider.chainId
219
+ );
220
+ if (migrationBot) {
221
+ const result = await this.provider.publicClient.multicall({
222
+ contracts: accountsToCheck.map((ca) => {
223
+ const cm = this.sdk.marketRegister.findCreditManager(
224
+ ca.creditManager
225
+ );
226
+ return {
227
+ abi: (0, import_constants.isV300)(cm.creditFacade.version) ? import_v300.iBotListV300Abi : import_v310.iBotListV310Abi,
228
+ address: cm.creditFacade.botList,
229
+ functionName: "getBotStatus",
230
+ args: (0, import_constants.isV300)(cm.creditFacade.version) ? [migrationBot.botAddress, ca.creditManager, ca.creditAccount] : [migrationBot.botAddress, ca.creditAccount]
231
+ };
232
+ }),
233
+ allowFailure: true
234
+ });
235
+ return { result, migrationBot };
236
+ }
237
+ return void 0;
210
238
  }
211
239
  /**
212
240
  * Generates transaction to liquidate credit account
@@ -25,6 +25,9 @@ var import_bot_permissions = require("../constants/bot-permissions.js");
25
25
  const PERMISSION_BY_TYPE = {
26
26
  LIQUIDATION_PROTECTION: BigInt(
27
27
  import_bot_permissions.BotPermissions.ADD_COLLATERAL | import_bot_permissions.BotPermissions.WITHDRAW_COLLATERAL | import_bot_permissions.BotPermissions.DECREASE_DEBT
28
+ ),
29
+ MIGRATION: BigInt(
30
+ import_bot_permissions.BotPermissions.EXTERNAL_CALLS | import_bot_permissions.BotPermissions.UPDATE_QUOTA | import_bot_permissions.BotPermissions.DECREASE_DEBT
28
31
  )
29
32
  };
30
33
  // Annotate the CommonJS export names for ESM import in node:
@@ -15,6 +15,7 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var sdk_exports = {};
17
17
  module.exports = __toCommonJS(sdk_exports);
18
+ __reExport(sdk_exports, require("./accountMigration/index.js"), module.exports);
18
19
  __reExport(sdk_exports, require("./accounts/index.js"), module.exports);
19
20
  __reExport(sdk_exports, require("./base/index.js"), module.exports);
20
21
  __reExport(sdk_exports, require("./chain/index.js"), module.exports);
@@ -33,6 +34,7 @@ __reExport(sdk_exports, require("./utils/index.js"), module.exports);
33
34
  __reExport(sdk_exports, require("./utils/viem/index.js"), module.exports);
34
35
  // Annotate the CommonJS export names for ESM import in node:
35
36
  0 && (module.exports = {
37
+ ...require("./accountMigration/index.js"),
36
38
  ...require("./accounts/index.js"),
37
39
  ...require("./base/index.js"),
38
40
  ...require("./chain/index.js"),
@@ -35,6 +35,7 @@ __export(transactions_exports, {
35
35
  TxGaugeVote: () => TxGaugeVote,
36
36
  TxIncreaseBorrowAmount: () => TxIncreaseBorrowAmount,
37
37
  TxLiquidateAccount: () => TxLiquidateAccount,
38
+ TxMigrateCreditAccount: () => TxMigrateCreditAccount,
38
39
  TxOpenMultitokenAccount: () => TxOpenMultitokenAccount,
39
40
  TxRemoveBot: () => TxRemoveBot,
40
41
  TxRemoveLiquidity: () => TxRemoveLiquidity,
@@ -111,6 +112,8 @@ class TxSerializer {
111
112
  return new TxFillOrder(params);
112
113
  case "TxStartDelayedWithdrawal":
113
114
  return new TxStartDelayedWithdrawal(params);
115
+ case "TxMigrateCreditAccount":
116
+ return new TxMigrateCreditAccount(params);
114
117
  default:
115
118
  throw new Error(`Unknown transaction for parsing: ${e.type}`);
116
119
  }
@@ -446,6 +449,22 @@ class TxStartDelayedWithdrawal extends import_eventOrTx.EVMTx {
446
449
  };
447
450
  }
448
451
  }
452
+ class TxMigrateCreditAccount extends import_eventOrTx.EVMTx {
453
+ targetCreditManager;
454
+ constructor(opts) {
455
+ super(opts);
456
+ this.targetCreditManager = `${opts.targetCreditManager.name} (${opts.curatorName})`;
457
+ }
458
+ toString() {
459
+ return `Successfully migrated Credit Account to ${this.targetCreditManager}`;
460
+ }
461
+ serialize() {
462
+ return {
463
+ type: "TxMigrateCreditAccount",
464
+ content: JSON.stringify(this)
465
+ };
466
+ }
467
+ }
449
468
  class TxRepayAccount extends import_eventOrTx.EVMTx {
450
469
  creditManagerName;
451
470
  constructor(opts) {
@@ -737,6 +756,7 @@ class TxFillOrder extends import_eventOrTx.EVMTx {
737
756
  TxGaugeVote,
738
757
  TxIncreaseBorrowAmount,
739
758
  TxLiquidateAccount,
759
+ TxMigrateCreditAccount,
740
760
  TxOpenMultitokenAccount,
741
761
  TxRemoveBot,
742
762
  TxRemoveLiquidity,
@@ -11,7 +11,7 @@ import {
11
11
  import { PartialLiquidationBotV300Contract } from "./PartialLiquidationBotV300Contract.js";
12
12
  import { PartialLiquidationBotV310Contract } from "./PartialLiquidationBotV310Contract.js";
13
13
  import {
14
- BOT_TYPES
14
+ LIQUIDATION_BOT_TYPES
15
15
  } from "./types.js";
16
16
  class UnsupportedBotVersionError extends Error {
17
17
  state;
@@ -65,7 +65,7 @@ class BotsPlugin extends BasePlugin {
65
65
  throw new Error(`expected 4 bots v300 for market configurator ${mc}`);
66
66
  }
67
67
  for (let i = 0; i < bots.length; i++) {
68
- bots[i].botType = BOT_TYPES[i];
68
+ bots[i].botType = LIQUIDATION_BOT_TYPES[i];
69
69
  }
70
70
  }
71
71
  this.botsByMarket.upsert(mc, bots);
@@ -1,9 +1,9 @@
1
- const BOT_TYPES = [
1
+ const LIQUIDATION_BOT_TYPES = [
2
2
  "PARTIAL_LIQUIDATION_BOT",
3
3
  "DELEVERAGE_BOT_PEGGED",
4
4
  "DELEVERAGE_BOT_LV",
5
5
  "DELEVERAGE_BOT_HV"
6
6
  ];
7
7
  export {
8
- BOT_TYPES
8
+ LIQUIDATION_BOT_TYPES
9
9
  };