@gearbox-protocol/sdk 13.5.0-next.1 → 13.5.0-next.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.
Files changed (56) hide show
  1. package/dist/cjs/dev/AccountOpener.js +5 -45
  2. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +6 -339
  3. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +1 -13
  4. package/dist/cjs/sdk/base/TokensMeta.js +7 -151
  5. package/dist/cjs/sdk/base/token-types.js +0 -6
  6. package/dist/cjs/sdk/chain/chains.js +1 -2
  7. package/dist/cjs/sdk/constants/addresses.js +3 -0
  8. package/dist/cjs/sdk/market/MarketRegister.js +0 -3
  9. package/dist/cjs/sdk/market/MarketSuite.js +0 -3
  10. package/dist/cjs/sdk/market/ZapperRegister.js +0 -4
  11. package/dist/cjs/sdk/market/pool/PoolSuite.js +0 -3
  12. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +2 -17
  13. package/dist/cjs/sdk/market/pool/index.js +0 -4
  14. package/dist/cjs/sdk/pools/PoolService.js +43 -122
  15. package/dist/cjs/sdk/pools/constants.js +37 -0
  16. package/dist/esm/dev/AccountOpener.js +6 -47
  17. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +6 -339
  18. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +1 -13
  19. package/dist/esm/sdk/base/TokensMeta.js +7 -155
  20. package/dist/esm/sdk/base/token-types.js +0 -4
  21. package/dist/esm/sdk/chain/chains.js +1 -2
  22. package/dist/esm/sdk/constants/addresses.js +2 -0
  23. package/dist/esm/sdk/market/MarketRegister.js +0 -3
  24. package/dist/esm/sdk/market/MarketSuite.js +0 -3
  25. package/dist/esm/sdk/market/ZapperRegister.js +0 -4
  26. package/dist/esm/sdk/market/pool/PoolSuite.js +0 -3
  27. package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -17
  28. package/dist/esm/sdk/market/pool/index.js +0 -2
  29. package/dist/esm/sdk/pools/PoolService.js +32 -115
  30. package/dist/esm/sdk/pools/constants.js +13 -0
  31. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +5 -103
  32. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +2 -4
  33. package/dist/types/sdk/accounts/types.d.ts +6 -130
  34. package/dist/types/sdk/base/TokensMeta.d.ts +3 -20
  35. package/dist/types/sdk/base/token-types.d.ts +1 -21
  36. package/dist/types/sdk/base/types.d.ts +3 -0
  37. package/dist/types/sdk/chain/chains.d.ts +1 -1
  38. package/dist/types/sdk/constants/addresses.d.ts +4 -0
  39. package/dist/types/sdk/market/MarketSuite.d.ts +0 -2
  40. package/dist/types/sdk/market/pool/PoolSuite.d.ts +0 -2
  41. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +2 -6
  42. package/dist/types/sdk/market/pool/index.d.ts +0 -2
  43. package/dist/types/sdk/market/types.d.ts +1 -1
  44. package/dist/types/sdk/pools/PoolService.d.ts +24 -0
  45. package/dist/types/sdk/pools/constants.d.ts +7 -0
  46. package/dist/types/sdk/pools/types.d.ts +9 -8
  47. package/package.json +1 -1
  48. package/dist/cjs/abi/310/iSecuritizeDegenNFT.js +0 -263
  49. package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +0 -278
  50. package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +0 -97
  51. package/dist/esm/abi/310/iSecuritizeDegenNFT.js +0 -239
  52. package/dist/esm/abi/310/iSecuritizeKYCFactory.js +0 -254
  53. package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +0 -73
  54. package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +0 -324
  55. package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +0 -322
  56. package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +0 -345
@@ -0,0 +1,37 @@
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 constants_exports = {};
20
+ __export(constants_exports, {
21
+ POOL_TOKENS_TO_MIGRATE: () => POOL_TOKENS_TO_MIGRATE
22
+ });
23
+ module.exports = __toCommonJS(constants_exports);
24
+ var import_utils = require("../utils/index.js");
25
+ const POOL_TOKENS_TO_MIGRATE = new import_utils.AddressMap([
26
+ // v2 diesels
27
+ ["0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA", "dDAI"],
28
+ ["0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3", "dUSDC"],
29
+ ["0xe753260F1955e8678DCeA8887759e07aa57E8c54", "dWBTC"],
30
+ ["0xF21fc650C1B34eb0FDE786D52d23dA99Db3D6278", "dWETH"],
31
+ ["0x2158034dB06f06dcB9A786D2F1F8c38781bA779d", "dwstETH"],
32
+ ["0x8A1112AFef7F4FC7c066a77AABBc01b3Fff31D47", "dFRAX"]
33
+ ]);
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ POOL_TOKENS_TO_MIGRATE
37
+ });
@@ -6,7 +6,7 @@ import {
6
6
  parseEventLogs
7
7
  } from "viem";
8
8
  import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
9
- import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
9
+ import { iCreditFacadeV310Abi, iPoolV310Abi } from "../abi/310/generated.js";
10
10
  import { ierc20Abi } from "../abi/iERC20.js";
11
11
  import {
12
12
  ADDRESS_0X0,
@@ -15,7 +15,6 @@ import {
15
15
  childLogger,
16
16
  MAX_UINT256,
17
17
  PERCENTAGE_FACTOR,
18
- PoolService,
19
18
  SDKConstruct,
20
19
  sendRawTx
21
20
  } from "../sdk/index.js";
@@ -44,7 +43,6 @@ class AccountOpener extends SDKConstruct {
44
43
  #minDebtMultiplier;
45
44
  #allowMint;
46
45
  #leverageDelta;
47
- #poolService;
48
46
  constructor(service, options_ = {}) {
49
47
  super(service.sdk);
50
48
  const {
@@ -70,7 +68,6 @@ class AccountOpener extends SDKConstruct {
70
68
  this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
71
69
  this.#minDebtMultiplier = BigInt(minDebtMultiplier);
72
70
  this.#leverageDelta = BigInt(leverageDelta);
73
- this.#poolService = new PoolService(service.sdk);
74
71
  this.#logger?.info(
75
72
  {
76
73
  borrower: privateKeyToAccount(this.borrowerKey).address,
@@ -108,10 +105,6 @@ class AccountOpener extends SDKConstruct {
108
105
  },
109
106
  "opening credit accounts"
110
107
  );
111
- await Promise.all([
112
- this.sdk.tokensMeta.loadTokenData(),
113
- this.sdk.marketRegister.loadZappers()
114
- ]);
115
108
  let deposits = [];
116
109
  if (depositIntoPools) {
117
110
  try {
@@ -463,34 +456,9 @@ class AccountOpener extends SDKConstruct {
463
456
  this.#logger?.debug(
464
457
  `depositor balance in underlying: ${this.sdk.tokensMeta.formatBN(pool.underlying, allowance, { symbol: true })}`
465
458
  );
466
- const tokensOut = this.#poolService.getDepositTokensOut(
467
- address,
468
- underlying
469
- );
470
- this.#logger?.debug(
471
- { tokensOut: tokensOut.map((t) => this.labelAddress(t)) },
472
- "deposit tokens out"
473
- );
474
- if (tokensOut.length === 0) {
475
- throw new Error(`no tokens out found for pool ${poolName}`);
476
- }
477
- const tokenOut = tokensOut[0];
478
- const metadata = this.#poolService.getDepositMetadata(
479
- address,
480
- underlying,
481
- tokenOut
482
- );
483
- this.logger?.debug(
484
- {
485
- underlying: this.labelAddress(underlying),
486
- tokenOut: this.labelAddress(tokenOut),
487
- ...metadata
488
- },
489
- "pool deposit metadata"
490
- );
491
459
  txHash = await this.#anvil.writeContract({
492
460
  account: depositor,
493
- address: metadata.approveTarget,
461
+ address: underlying,
494
462
  abi: ierc20Abi,
495
463
  functionName: "approve",
496
464
  args: [address, allowance],
@@ -507,21 +475,12 @@ class AccountOpener extends SDKConstruct {
507
475
  this.#logger?.debug(
508
476
  `depositor approved underlying for pool ${poolName}: ${txHash}`
509
477
  );
510
- const depositCall = this.#poolService.addLiquidity({
511
- collateral: { token: underlying, balance: amount },
512
- pool: address,
513
- wallet: depositor.address,
514
- meta: metadata
515
- });
516
- if (!depositCall) {
517
- throw new Error(`no deposit call could be created for ${poolName}`);
518
- }
519
478
  txHash = await this.#anvil.writeContract({
520
479
  account: depositor,
521
- address: depositCall.target,
522
- abi: depositCall.abi,
523
- functionName: depositCall.functionName,
524
- args: depositCall.args,
480
+ address,
481
+ abi: iPoolV310Abi,
482
+ functionName: "deposit",
483
+ args: [amount, depositor.address],
525
484
  chain: this.#anvil.chain
526
485
  });
527
486
  receipt = await this.#anvil.waitForTransactionReceipt({ hash: txHash });
@@ -1,4 +1,3 @@
1
- import { ierc4626AdapterAbi } from "@gearbox-protocol/integrations-v3";
2
1
  import { encodeFunctionData, getContract } from "viem";
3
2
  import {
4
3
  iBotListV310Abi,
@@ -91,23 +90,6 @@ class AbstractCreditAccountService extends SDKConstruct {
91
90
  });
92
91
  return cad;
93
92
  }
94
- /**
95
- * Returns credit account data for a single account with the investor address resolved.
96
- * Loads CA via getCreditAccountData; for KYC underlyings fetches the investor from the KYC factory's getInvestor(creditAccount), otherwise uses the account owner.
97
- * @param account - Credit account address
98
- * @param blockNumber - Optional block number for the read
99
- * @returns CreditAccountDataWithInvestor (CA data + investor address), or undefined if the account is not found
100
- */
101
- async getCreditAccountDataWithInvestor(account, blockNumber) {
102
- const ca = await this.getCreditAccountData(account, blockNumber);
103
- if (!ca) return ca;
104
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
105
- ca.creditManager
106
- );
107
- const factory = await marketSuite.getKYCFactory();
108
- const investor = factory ? await factory.getInvestor(ca.creditAccount, true) : void 0;
109
- return { ...ca, investor: investor ?? ca.owner };
110
- }
111
93
  /**
112
94
  * {@inheritDoc ICreditAccountsService.getCreditAccounts}
113
95
  **/
@@ -162,75 +144,6 @@ class AbstractCreditAccountService extends SDKConstruct {
162
144
  );
163
145
  return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
164
146
  }
165
- /**
166
- * Returns all credit accounts matching the filter, with investor set on each item.
167
- * Delegates to getCreditAccounts; when options.owner is set, also loads KYC credit accounts for that owner and merges them into the list. Result is sorted by health factor ascending.
168
- * @param options - Filter options (owner, creditManager, health factor, etc.)
169
- * @param blockNumber - Optional block number for the read
170
- * @returns Array of credit accounts (with investor field), sorted by health factor ascending
171
- */
172
- async getCreditAccountsWithInvestor(options, blockNumber) {
173
- const { owner, ignoreReservePrices = false } = options ?? {};
174
- const priceUpdate = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
175
- ignoreReservePrices ? { main: true } : void 0
176
- );
177
- const { txs: priceUpdateTxs } = priceUpdate;
178
- const [common, kyc] = await Promise.all([
179
- this.getCreditAccounts(options, blockNumber),
180
- owner ? this.getKYCCreditAccountsOfOwner(owner, priceUpdateTxs, blockNumber) : void 0
181
- ]);
182
- const allCAs = common.map(
183
- (ca) => ({
184
- ...ca,
185
- investor: owner || ca.owner
186
- })
187
- );
188
- allCAs.push(...kyc || []);
189
- return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
190
- }
191
- async getKYCCreditAccountsOfOwner(owner, priceUpdateTxs, blockNumber) {
192
- const suites = this.marketConfigurators.map((mc) => {
193
- const suite = this.sdk.marketRegister.markets.find(
194
- (m) => m.configurator.address === mc
195
- );
196
- return suite;
197
- });
198
- const kycCAAddresses = await this.getKYCCaOfInvestor(owner, suites);
199
- const kycCAs = await this.loadSpecifiedAccounts(
200
- kycCAAddresses,
201
- priceUpdateTxs,
202
- blockNumber
203
- );
204
- return kycCAs.map((ca) => ({
205
- ...ca,
206
- investor: owner
207
- }));
208
- }
209
- /**
210
- * Loads credit account data for the given addresses using simulateWithPriceUpdates.
211
- * Applies the provided price update txs before reading, so returned data is consistent with up-to-date prices.
212
- * @param accounts - Credit account addresses to load
213
- * @param priceUpdateTxs - Price feed update txs to simulate before the read (e.g. from generatePriceFeedsUpdateTxs)
214
- * @param blockNumber - Optional block number for the read
215
- * @returns Array of CreditAccountData in the same order as accounts (throws if any getCreditAccountData call reverts)
216
- */
217
- async loadSpecifiedAccounts(accounts, priceUpdateTxs, blockNumber) {
218
- if (accounts.length === 0) return [];
219
- const list = await simulateWithPriceUpdates(this.client, {
220
- priceUpdates: priceUpdateTxs,
221
- contracts: accounts.map(
222
- (account) => ({
223
- abi: creditAccountCompressorAbi,
224
- address: this.#compressor,
225
- functionName: "getCreditAccountData",
226
- args: [account]
227
- })
228
- ),
229
- blockNumber,
230
- gas: this.sdk.gasLimit
231
- });
232
- return list;
233
- }
234
147
  /**
235
148
  * {@inheritDoc ICreditAccountsService.getRewards}
236
149
  **/
@@ -335,19 +248,19 @@ class AbstractCreditAccountService extends SDKConstruct {
335
248
  );
336
249
  return {
337
250
  legacy,
338
- additionalBots: this.getActiveBots(
251
+ additionalBots: this.#getActiveBots(
339
252
  accountsToCheck,
340
253
  additionalBots,
341
254
  additionalResp
342
255
  ),
343
- legacyMigration: this.getActiveMigrationBots(
256
+ legacyMigration: this.#getActiveMigrationBots(
344
257
  accountsToCheck,
345
258
  legacyMigrationBot,
346
259
  migrationResp
347
260
  )
348
261
  };
349
262
  }
350
- getActiveBots(accountsToCheck, bots, result) {
263
+ #getActiveBots(accountsToCheck, bots, result) {
351
264
  if (result.length !== bots.length * accountsToCheck.length) {
352
265
  console.error(
353
266
  "result length mismatch",
@@ -364,7 +277,7 @@ class AbstractCreditAccountService extends SDKConstruct {
364
277
  }, []);
365
278
  return botsByCAIndex;
366
279
  }
367
- getActiveMigrationBots(accountsToCheck, bot, result) {
280
+ #getActiveMigrationBots(accountsToCheck, bot, result) {
368
281
  if (bot) {
369
282
  if (result.length !== accountsToCheck.length) {
370
283
  console.error(
@@ -440,13 +353,6 @@ class AbstractCreditAccountService extends SDKConstruct {
440
353
  closePath
441
354
  }) {
442
355
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
443
- await this.sdk.tokensMeta.loadTokenData(cm.underlying);
444
- const underlying = this.sdk.tokensMeta.mustGet(cm.underlying);
445
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
446
- throw new Error(
447
- "closeCreditAccount is not supported for KYC underlying credit accounts"
448
- );
449
- }
450
356
  const routerCloseResult = closePath || await this.sdk.routerFor(ca).findBestClosePath({
451
357
  creditAccount: ca,
452
358
  creditManager: cm.creditManager,
@@ -552,18 +458,8 @@ class AbstractCreditAccountService extends SDKConstruct {
552
458
  ],
553
459
  {}
554
460
  ) : [];
555
- const unwrapCalls = collateral && isDecrease ? await this.getKYCUnwrapCalls(
556
- collateral[0].balance,
557
- creditAccount.creditManager
558
- ) || [] : [];
559
- if (addCollateralCalls.length > 0 && unwrapCalls.length === 0 && collateral && collateral?.[0].token !== creditAccount.underlying) {
560
- throw new Error(
561
- "Can't use collateral other than underlying for non KYC market"
562
- );
563
- }
564
461
  const operationCalls = [
565
462
  ...addCollateralCalls,
566
- ...unwrapCalls,
567
463
  this.#prepareChangeDebt(creditAccount.creditFacade, change, isDecrease)
568
464
  ];
569
465
  const calls = await this.prependPriceUpdates(
@@ -771,25 +667,6 @@ class AbstractCreditAccountService extends SDKConstruct {
771
667
  const tx = await this.multicallTx(cm, creditAccount.creditAccount, calls);
772
668
  return { tx, calls, creditFacade: cm.creditFacade };
773
669
  }
774
- /**
775
- * Returns address to which approval should be given on collateral token
776
- * It's credit manager for classical markets and special wallet for KYC markets
777
- * @param options - {@link GetApprovalAddressProps}
778
- * @returns
779
- **/
780
- async getApprovalAddress(options) {
781
- const { creditManager } = options;
782
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
783
- const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
784
- const factory = await marketSuite.getKYCFactory();
785
- if (factory) {
786
- if ("creditAccount" in options) {
787
- return factory.getWallet(options.creditAccount);
788
- }
789
- return factory.precomputeWalletAddress(creditManager, options.borrower);
790
- }
791
- return suite.creditManager.address;
792
- }
793
670
  /**
794
671
  * {@inheritDoc ICreditAccountsService.openCA}
795
672
  **/
@@ -924,131 +801,6 @@ class AbstractCreditAccountService extends SDKConstruct {
924
801
  return resp;
925
802
  }
926
803
  /**
927
- * Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
928
- * Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
929
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
930
- * @param amount - Number of vault shares (adapter tokens) to redeem
931
- * @param creditManager - Credit manager address
932
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
933
- */
934
- async getKYCUnwrapCalls(amount, creditManager) {
935
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
936
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
937
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
938
- return void 0;
939
- }
940
- const adapter = suite.creditManager.adapters.get(meta.addr);
941
- const adapterAddress = adapter?.address;
942
- if (!adapterAddress) {
943
- return void 0;
944
- }
945
- const mc = [
946
- {
947
- target: adapterAddress,
948
- callData: encodeFunctionData({
949
- abi: ierc4626AdapterAbi,
950
- functionName: "redeem",
951
- args: [amount, ADDRESS_0X0, ADDRESS_0X0]
952
- })
953
- }
954
- ];
955
- return mc;
956
- }
957
- /**
958
- * Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
959
- * Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
960
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
961
- * @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
962
- * @param creditManager - Credit manager address
963
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
964
- */
965
- async getKYCWrapCalls(amount, creditManager) {
966
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
967
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
968
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
969
- return void 0;
970
- }
971
- const adapter = suite.creditManager.adapters.get(meta.addr);
972
- const adapterAddress = adapter?.address;
973
- if (!adapterAddress) {
974
- return void 0;
975
- }
976
- const mc = [
977
- {
978
- target: adapterAddress,
979
- callData: encodeFunctionData({
980
- abi: ierc4626AdapterAbi,
981
- functionName: "deposit",
982
- args: [amount, ADDRESS_0X0]
983
- })
984
- }
985
- ];
986
- return mc;
987
- }
988
- /**
989
- * Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
990
- * Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
991
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
992
- * @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
993
- * @param creditManager - Credit manager address
994
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
995
- */
996
- async getRedeemDiffCalls(amount, creditManager) {
997
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
998
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
999
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
1000
- return void 0;
1001
- }
1002
- const adapter = suite.creditManager.adapters.get(meta.addr);
1003
- const adapterAddress = adapter?.address;
1004
- if (!adapterAddress) {
1005
- return void 0;
1006
- }
1007
- const mc = [
1008
- {
1009
- target: adapterAddress,
1010
- callData: encodeFunctionData({
1011
- abi: ierc4626AdapterAbi,
1012
- functionName: "redeemDiff",
1013
- args: [amount]
1014
- })
1015
- }
1016
- ];
1017
- return mc;
1018
- }
1019
- /**
1020
- * Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
1021
- * Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
1022
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
1023
- * @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
1024
- * @param creditManager - Credit manager address
1025
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
1026
- */
1027
- async getDepositDiffCalls(amount, creditManager) {
1028
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
1029
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
1030
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
1031
- return void 0;
1032
- }
1033
- const adapter = suite.creditManager.adapters.get(meta.addr);
1034
- const adapterAddress = adapter?.address;
1035
- if (!adapterAddress) {
1036
- return void 0;
1037
- }
1038
- const mc = [
1039
- {
1040
- target: adapterAddress,
1041
- callData: encodeFunctionData({
1042
- abi: ierc4626AdapterAbi,
1043
- functionName: "depositDiff",
1044
- args: [amount]
1045
- })
1046
- }
1047
- ];
1048
- return mc;
1049
- }
1050
- /**
1051
- * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
1052
804
  * {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
1053
805
  **/
1054
806
  async getOnDemandPriceUpdates(account, ignoreReservePrices) {
@@ -1143,13 +895,7 @@ class AbstractCreditAccountService extends SDKConstruct {
1143
895
  return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
1144
896
  }
1145
897
  /**
1146
- * Executes a multicall on a credit account, automatically prepending
1147
- * necessary on-demand price feed updates.
1148
- *
1149
- * @param creditAccount - Credit account to execute multicall on
1150
- * @param calls - Array of multicall operations (price updates will be inferred)
1151
- * @param options - Optional settings for price update generation
1152
- * @returns Raw transaction ready to be signed and sent
898
+ * {@inheritDoc ICreditAccountsService.multicall}
1153
899
  */
1154
900
  async multicall(creditAccount, calls, options) {
1155
901
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -1167,13 +913,7 @@ class AbstractCreditAccountService extends SDKConstruct {
1167
913
  );
1168
914
  }
1169
915
  /**
1170
- * Executes a bot multicall on a credit account, automatically prepending
1171
- * necessary on-demand price feed updates.
1172
- *
1173
- * @param creditAccount - Credit account to execute bot multicall on
1174
- * @param calls - Array of multicall operations (price updates will be inferred)
1175
- * @param options - Optional settings for price update generation
1176
- * @returns Raw transaction ready to be signed and sent
916
+ * {@inheritDoc ICreditAccountsService.botMulticall}
1177
917
  */
1178
918
  async botMulticall(creditAccount, calls, options) {
1179
919
  const cm = this.sdk.marketRegister.findCreditManager(
@@ -1318,16 +1058,6 @@ class AbstractCreditAccountService extends SDKConstruct {
1318
1058
  * @returns
1319
1059
  */
1320
1060
  async openCreditAccountTx(suite, to, calls, referralCode) {
1321
- const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
1322
- const factory = await marketSuite.getKYCFactory();
1323
- if (factory) {
1324
- const tokensToRegister = await factory.getDSTokens();
1325
- return factory.openCreditAccount(
1326
- suite.creditManager.address,
1327
- calls,
1328
- tokensToRegister
1329
- );
1330
- }
1331
1061
  return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
1332
1062
  }
1333
1063
  /**
@@ -1338,14 +1068,6 @@ class AbstractCreditAccountService extends SDKConstruct {
1338
1068
  * @returns
1339
1069
  */
1340
1070
  async multicallTx(suite, creditAccount, calls) {
1341
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
1342
- suite.creditManager.address
1343
- );
1344
- const factory = await marketSuite.getKYCFactory();
1345
- if (factory) {
1346
- const tokensToRegister = [];
1347
- return factory.multicall(creditAccount, calls, tokensToRegister);
1348
- }
1349
1071
  return suite.creditFacade.multicall(creditAccount, calls);
1350
1072
  }
1351
1073
  /**
@@ -1357,66 +1079,11 @@ class AbstractCreditAccountService extends SDKConstruct {
1357
1079
  * @returns
1358
1080
  */
1359
1081
  async closeCreditAccountTx(suite, creditAccount, calls, operation) {
1360
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
1361
- suite.creditManager.address
1362
- );
1363
- const factory = await marketSuite.getKYCFactory();
1364
1082
  if (operation === "close") {
1365
- if (factory) {
1366
- throw new Error(
1367
- "CloseOptions=close is not supported for KYC underlying credit accounts"
1368
- );
1369
- }
1370
1083
  return suite.creditFacade.closeCreditAccount(creditAccount, calls);
1371
1084
  }
1372
- if (factory) {
1373
- const tokensToRegister = [];
1374
- return factory.multicall(creditAccount, calls, tokensToRegister);
1375
- }
1376
1085
  return suite.creditFacade.multicall(creditAccount, calls);
1377
1086
  }
1378
- /**
1379
- * Returns all KYC credit account addresses for an investor across the given market suites.
1380
- * Resolves KYC factory per suite, then multicalls each factory's getCreditAccounts(investor).
1381
- * @param investor - Owner address to query
1382
- * @param suites - Market suites (KYC factories are resolved for each; undefined entries are skipped)
1383
- * @returns Flat array of credit account addresses from all KYC markets
1384
- */
1385
- async getKYCCaOfInvestor(investor, suites) {
1386
- if (suites.length === 0 || investor === ADDRESS_0X0) return [];
1387
- const factories = await Promise.all(
1388
- suites.map((suite) => suite ? suite.getKYCFactory() : void 0)
1389
- );
1390
- const safeFactories = factories.reduce(
1391
- (acc, v) => {
1392
- if (v) {
1393
- acc.push(v);
1394
- }
1395
- return acc;
1396
- },
1397
- []
1398
- );
1399
- const allResp = await this.client.multicall({
1400
- contracts: [
1401
- ...safeFactories.map((factory) => {
1402
- return {
1403
- abi: factory.abi,
1404
- address: factory.address,
1405
- functionName: "getCreditAccounts",
1406
- args: [investor]
1407
- };
1408
- })
1409
- ],
1410
- allowFailure: true,
1411
- batchSize: 0
1412
- });
1413
- const caLists = safeFactories.reduce((acc, _, index) => {
1414
- const response = allResp[index];
1415
- acc.push(...response.result || []);
1416
- return acc;
1417
- }, []);
1418
- return caLists;
1419
- }
1420
1087
  }
1421
1088
  export {
1422
1089
  AbstractCreditAccountService,
@@ -90,23 +90,19 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
90
90
  creditAccount: ca,
91
91
  permits,
92
92
  to,
93
- tokensToClaim,
94
- calls: wrapCalls = []
93
+ tokensToClaim
95
94
  }) {
96
95
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
97
96
  const addCollateral = collateralAssets.filter((a) => a.balance > 0);
98
97
  const router = this.sdk.routerFor(ca);
99
- const unwrapCalls = await this.getRedeemDiffCalls(1n, ca.creditManager) ?? [];
100
98
  const claimPath = await router.findClaimAllRewards({
101
99
  tokensToClaim,
102
100
  creditAccount: ca
103
101
  });
104
102
  const operationCalls = [
105
103
  ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
106
- ...wrapCalls,
107
104
  ...this.prepareDisableQuotas(ca),
108
105
  ...this.prepareDecreaseDebt(ca),
109
- ...unwrapCalls,
110
106
  ...claimPath.calls,
111
107
  ...assetsToWithdraw.map(
112
108
  (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, MAX_UINT256, to)
@@ -138,12 +134,10 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
138
134
  tokensToClaim,
139
135
  creditAccount: ca
140
136
  });
141
- const wrapCalls = await this.getDepositDiffCalls(1n, ca.creditManager) ?? [];
142
137
  const addCollateral = collateralAssets.filter((a) => a.balance > 0);
143
138
  const operationCalls = [
144
139
  ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
145
140
  ...claimPath.calls,
146
- ...wrapCalls,
147
141
  ...assetsToWithdraw.map(
148
142
  (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, MAX_UINT256, to)
149
143
  )
@@ -194,12 +188,6 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
194
188
  const tx = await this.multicallTx(cm, ca.creditAccount, calls);
195
189
  return { tx, calls, creditFacade: cm.creditFacade };
196
190
  }
197
- async previewWithdrawLlamathenaProportionally(_) {
198
- throw new Error("Not implemented in v310");
199
- }
200
- async withdrawLlamathenaProportionally(_) {
201
- throw new Error("Not implemented in v310");
202
- }
203
191
  }
204
192
  export {
205
193
  CreditAccountServiceV310