@gearbox-protocol/sdk 8.27.0 → 8.27.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.
@@ -175,11 +175,27 @@ class AbstractMigrateCreditAccountsService extends import_base.SDKConstruct {
175
175
  });
176
176
  return !!adapter;
177
177
  }
178
- static isSourceMigratableToTargetCM(targetTokensToMigrate, source, target, delayedPhantoms) {
179
- const debt = source.borrowedAmountPlusInterestAndFees;
180
- if (debt > target.maxDebt || debt < target.minDebt) return false;
178
+ static isSourceMigratableToTargetCM(targetTokensToMigrate, source, target, delayedPhantoms, sdk) {
181
179
  const sourceUnderlying = source.underlying;
182
- if (!target.supportedTokens[sourceUnderlying]) return false;
180
+ if (!target.supportedTokens[sourceUnderlying]) {
181
+ return false;
182
+ }
183
+ const tryConvert = () => {
184
+ try {
185
+ const market = sdk.marketRegister.findByCreditManager(target.address);
186
+ return market.priceOracle.convert(
187
+ sourceUnderlying,
188
+ target.underlyingToken,
189
+ source.borrowedAmountPlusInterestAndFees
190
+ );
191
+ } catch (e) {
192
+ return 0n;
193
+ }
194
+ };
195
+ const debt = source.underlying !== target.underlyingToken ? tryConvert() : source.borrowedAmountPlusInterestAndFees;
196
+ if (debt === 0n || debt > target.maxDebt || debt < target.minDebt) {
197
+ return false;
198
+ }
183
199
  const collateralsCheckPassed = targetTokensToMigrate.every((a) => {
184
200
  const tokenToMigrate = AbstractMigrateCreditAccountsService.getV310TargetTokenAddress(
185
201
  a.token,
@@ -518,7 +518,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
518
518
  const multiAcceptContract = (0, import_viem.getContract)({
519
519
  address: mellowClaimerAdapter.address,
520
520
  abi: iMellowClaimerAdapterAbi,
521
- client: this.sdk.provider.publicClient
521
+ client: this.client
522
522
  });
523
523
  const indices = await multiAcceptContract.read.getMultiVaultSubvaultIndices(
524
524
  [sourceToken]
@@ -590,7 +590,7 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
590
590
  const multiAcceptContract = (0, import_viem.getContract)({
591
591
  address: mellowClaimerAdapter.address,
592
592
  abi: iMellowClaimerAdapterAbi,
593
- client: this.sdk.provider.publicClient
593
+ client: this.client
594
594
  });
595
595
  const indices = await multiAcceptContract.read.getUserSubvaultIndices([
596
596
  sourceToken,
@@ -1052,6 +1052,9 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1052
1052
  import_constants.VERSION_RANGE_310
1053
1053
  )[0];
1054
1054
  }
1055
+ get client() {
1056
+ return this.sdk.provider.publicClient;
1057
+ }
1055
1058
  }
1056
1059
  const iMellowClaimerAdapterAbi = [
1057
1060
  {
@@ -155,11 +155,27 @@ class AbstractMigrateCreditAccountsService extends SDKConstruct {
155
155
  });
156
156
  return !!adapter;
157
157
  }
158
- static isSourceMigratableToTargetCM(targetTokensToMigrate, source, target, delayedPhantoms) {
159
- const debt = source.borrowedAmountPlusInterestAndFees;
160
- if (debt > target.maxDebt || debt < target.minDebt) return false;
158
+ static isSourceMigratableToTargetCM(targetTokensToMigrate, source, target, delayedPhantoms, sdk) {
161
159
  const sourceUnderlying = source.underlying;
162
- if (!target.supportedTokens[sourceUnderlying]) return false;
160
+ if (!target.supportedTokens[sourceUnderlying]) {
161
+ return false;
162
+ }
163
+ const tryConvert = () => {
164
+ try {
165
+ const market = sdk.marketRegister.findByCreditManager(target.address);
166
+ return market.priceOracle.convert(
167
+ sourceUnderlying,
168
+ target.underlyingToken,
169
+ source.borrowedAmountPlusInterestAndFees
170
+ );
171
+ } catch (e) {
172
+ return 0n;
173
+ }
174
+ };
175
+ const debt = source.underlying !== target.underlyingToken ? tryConvert() : source.borrowedAmountPlusInterestAndFees;
176
+ if (debt === 0n || debt > target.maxDebt || debt < target.minDebt) {
177
+ return false;
178
+ }
163
179
  const collateralsCheckPassed = targetTokensToMigrate.every((a) => {
164
180
  const tokenToMigrate = AbstractMigrateCreditAccountsService.getV310TargetTokenAddress(
165
181
  a.token,
@@ -515,7 +515,7 @@ class AbstractCreditAccountService extends SDKConstruct {
515
515
  const multiAcceptContract = getContract({
516
516
  address: mellowClaimerAdapter.address,
517
517
  abi: iMellowClaimerAdapterAbi,
518
- client: this.sdk.provider.publicClient
518
+ client: this.client
519
519
  });
520
520
  const indices = await multiAcceptContract.read.getMultiVaultSubvaultIndices(
521
521
  [sourceToken]
@@ -587,7 +587,7 @@ class AbstractCreditAccountService extends SDKConstruct {
587
587
  const multiAcceptContract = getContract({
588
588
  address: mellowClaimerAdapter.address,
589
589
  abi: iMellowClaimerAdapterAbi,
590
- client: this.sdk.provider.publicClient
590
+ client: this.client
591
591
  });
592
592
  const indices = await multiAcceptContract.read.getUserSubvaultIndices([
593
593
  sourceToken,
@@ -1049,6 +1049,9 @@ class AbstractCreditAccountService extends SDKConstruct {
1049
1049
  VERSION_RANGE_310
1050
1050
  )[0];
1051
1051
  }
1052
+ get client() {
1053
+ return this.sdk.provider.publicClient;
1054
+ }
1052
1055
  }
1053
1056
  const iMellowClaimerAdapterAbi = [
1054
1057
  {
@@ -35,5 +35,5 @@ export declare abstract class AbstractMigrateCreditAccountsService extends SDKCo
35
35
  };
36
36
  static getTokensAfterMigration<T extends Asset>(balances: Array<T> | Record<Address, T>, chainId: number): Array<T>;
37
37
  static checkSourceCreditManager(sourceCreditManager: Address, migrationBot: Address, sdk: GearboxSDK): boolean;
38
- static isSourceMigratableToTargetCM(targetTokensToMigrate: Array<Asset>, source: CreditAccountData_Legacy, target: CreditManagerData_Legacy, delayedPhantoms: Record<Address, object>): boolean;
38
+ static isSourceMigratableToTargetCM(targetTokensToMigrate: Array<Asset>, source: CreditAccountData_Legacy, target: CreditManagerData_Legacy, delayedPhantoms: Record<Address, object>, sdk: GearboxSDK): boolean;
39
39
  }
@@ -1,4 +1,4 @@
1
- import type { Address } from "viem";
1
+ import type { Address, PublicClient } from "viem";
2
2
  import type { CreditAccountData } from "../base/index.js";
3
3
  import { SDKConstruct } from "../base/index.js";
4
4
  import type { GearboxSDK } from "../GearboxSDK.js";
@@ -213,4 +213,5 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
213
213
  private get marketConfigurators();
214
214
  private get rewardCompressor();
215
215
  private get peripheryCompressor();
216
+ get client(): PublicClient;
216
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "8.27.0",
3
+ "version": "8.27.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",