@gearbox-protocol/sdk 13.6.0-kyc.7 → 13.6.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 (152) hide show
  1. package/dist/cjs/dev/AccountOpener.js +5 -45
  2. package/dist/cjs/plugins/adapters/abi/actionAbi.js +1 -1
  3. package/dist/cjs/plugins/adapters/abi/conctructorAbi.js +1 -1
  4. package/dist/cjs/plugins/adapters/createAdapter.js +1 -1
  5. package/dist/cjs/plugins/adapters/types.js +1 -1
  6. package/dist/cjs/plugins/apy/ApyPlugin.js +266 -0
  7. package/dist/cjs/plugins/apy/apy-cache.js +120 -0
  8. package/dist/cjs/plugins/apy/apy-parser.js +169 -0
  9. package/dist/cjs/{sdk/market/kyc/securitize → plugins/apy}/constants.js +6 -3
  10. package/dist/cjs/{sdk/market/kyc/securitize → plugins/apy}/index.js +14 -6
  11. package/dist/cjs/{sdk/market/kyc/securitize/types.js → plugins/apy/pool-apy-types.js} +2 -2
  12. package/dist/cjs/plugins/apy/pool-apy-utils.js +141 -0
  13. package/dist/cjs/rewards/rewards/extra-apy.js +10 -8
  14. package/dist/cjs/sdk/GearboxSDK.js +5 -52
  15. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +16 -324
  16. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +1 -7
  17. package/dist/cjs/sdk/base/TokensMeta.js +43 -32
  18. package/dist/cjs/sdk/base/token-types.js +0 -9
  19. package/dist/cjs/sdk/chain/chains.js +32 -17
  20. package/dist/cjs/sdk/constants/address-provider.js +0 -3
  21. package/dist/cjs/sdk/market/MarketRegister.js +116 -70
  22. package/dist/cjs/sdk/market/MarketSuite.js +0 -3
  23. package/dist/cjs/sdk/market/index.js +0 -2
  24. package/dist/cjs/sdk/market/pool/PoolSuite.js +0 -3
  25. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +2 -11
  26. package/dist/cjs/sdk/market/pool/index.js +0 -2
  27. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  28. package/dist/cjs/sdk/options.js +1 -7
  29. package/dist/cjs/sdk/pools/PoolService.js +12 -104
  30. package/dist/cjs/sdk/utils/viem/index.js +0 -2
  31. package/dist/cjs/sdk/utils/viem/simulateWithPriceUpdates.js +39 -2
  32. package/dist/esm/dev/AccountOpener.js +6 -47
  33. package/dist/esm/plugins/adapters/abi/actionAbi.js +1 -1
  34. package/dist/esm/plugins/adapters/abi/conctructorAbi.js +1 -1
  35. package/dist/esm/plugins/adapters/createAdapter.js +1 -1
  36. package/dist/esm/plugins/adapters/types.js +1 -1
  37. package/dist/esm/plugins/apy/ApyPlugin.js +255 -0
  38. package/dist/esm/plugins/apy/apy-cache.js +86 -0
  39. package/dist/esm/plugins/apy/apy-parser.js +143 -0
  40. package/dist/esm/plugins/apy/constants.js +6 -0
  41. package/dist/esm/plugins/apy/index.js +7 -0
  42. package/dist/esm/plugins/apy/pool-apy-utils.js +113 -0
  43. package/dist/esm/rewards/rewards/extra-apy.js +10 -8
  44. package/dist/esm/sdk/GearboxSDK.js +6 -56
  45. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +17 -328
  46. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +1 -7
  47. package/dist/esm/sdk/base/TokensMeta.js +45 -32
  48. package/dist/esm/sdk/base/token-types.js +0 -6
  49. package/dist/esm/sdk/chain/chains.js +32 -17
  50. package/dist/esm/sdk/constants/address-provider.js +0 -2
  51. package/dist/esm/sdk/market/MarketRegister.js +118 -74
  52. package/dist/esm/sdk/market/MarketSuite.js +0 -3
  53. package/dist/esm/sdk/market/index.js +0 -1
  54. package/dist/esm/sdk/market/pool/PoolSuite.js +0 -3
  55. package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -11
  56. package/dist/esm/sdk/market/pool/index.js +0 -1
  57. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  58. package/dist/esm/sdk/options.js +1 -7
  59. package/dist/esm/sdk/pools/PoolService.js +13 -109
  60. package/dist/esm/sdk/utils/viem/index.js +0 -1
  61. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +41 -2
  62. package/dist/types/plugins/adapters/types.d.ts +2 -2
  63. package/dist/types/plugins/apy/ApyPlugin.d.ts +46 -0
  64. package/dist/types/plugins/apy/apy-cache.d.ts +28 -0
  65. package/dist/types/plugins/apy/apy-parser.d.ts +5 -0
  66. package/dist/types/plugins/apy/constants.d.ts +2 -0
  67. package/dist/types/plugins/apy/index.d.ts +7 -0
  68. package/dist/types/plugins/apy/pool-apy-types.d.ts +41 -0
  69. package/dist/types/plugins/apy/pool-apy-utils.d.ts +73 -0
  70. package/dist/types/plugins/apy/types.d.ts +37 -0
  71. package/dist/types/rewards/rewards/api.d.ts +10 -1
  72. package/dist/types/rewards/rewards/common.d.ts +0 -10
  73. package/dist/types/rewards/rewards/extra-apy.d.ts +4 -6
  74. package/dist/types/sdk/GearboxSDK.d.ts +0 -7
  75. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +2 -52
  76. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  77. package/dist/types/sdk/accounts/types.d.ts +13 -93
  78. package/dist/types/sdk/base/TokensMeta.d.ts +3 -14
  79. package/dist/types/sdk/base/token-types.d.ts +4 -44
  80. package/dist/types/sdk/base/types.d.ts +11 -116
  81. package/dist/types/sdk/chain/chains.d.ts +5 -5
  82. package/dist/types/sdk/constants/address-provider.d.ts +0 -1
  83. package/dist/types/sdk/market/MarketRegister.d.ts +9 -6
  84. package/dist/types/sdk/market/MarketSuite.d.ts +0 -2
  85. package/dist/types/sdk/market/index.d.ts +0 -1
  86. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +2 -3
  87. package/dist/types/sdk/market/oracle/types.d.ts +10 -3
  88. package/dist/types/sdk/market/pool/PoolSuite.d.ts +0 -2
  89. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +2 -6
  90. package/dist/types/sdk/market/pool/index.d.ts +0 -1
  91. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +1 -1
  92. package/dist/types/sdk/market/types.d.ts +1 -1
  93. package/dist/types/sdk/options.d.ts +0 -1
  94. package/dist/types/sdk/pools/PoolService.d.ts +8 -8
  95. package/dist/types/sdk/pools/types.d.ts +1 -1
  96. package/dist/types/sdk/types/state-human.d.ts +0 -2
  97. package/dist/types/sdk/types/state.d.ts +0 -5
  98. package/dist/types/sdk/utils/viem/index.d.ts +0 -1
  99. package/package.json +2 -3
  100. package/dist/cjs/abi/kyc/iDSRegistryService.js +0 -70
  101. package/dist/cjs/abi/kyc/iDSToken.js +0 -71
  102. package/dist/cjs/abi/kyc/iKYCCompressor.js +0 -196
  103. package/dist/cjs/abi/kyc/iKYCFactory.js +0 -122
  104. package/dist/cjs/abi/kyc/iKYCUnderlying.js +0 -401
  105. package/dist/cjs/abi/kyc/iSecuritizeDegenNFT.js +0 -326
  106. package/dist/cjs/abi/kyc/iSecuritizeKYCFactory.js +0 -319
  107. package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +0 -108
  108. package/dist/cjs/plugins/pools-history/index.js +0 -24
  109. package/dist/cjs/sdk/market/kyc/KYCRegistry.js +0 -269
  110. package/dist/cjs/sdk/market/kyc/index.js +0 -26
  111. package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +0 -244
  112. package/dist/cjs/sdk/market/kyc/types.js +0 -34
  113. package/dist/cjs/sdk/utils/viem/executeDelegatedMulticalls.js +0 -38
  114. package/dist/esm/abi/kyc/iDSRegistryService.js +0 -46
  115. package/dist/esm/abi/kyc/iDSToken.js +0 -47
  116. package/dist/esm/abi/kyc/iKYCCompressor.js +0 -172
  117. package/dist/esm/abi/kyc/iKYCFactory.js +0 -98
  118. package/dist/esm/abi/kyc/iKYCUnderlying.js +0 -377
  119. package/dist/esm/abi/kyc/iSecuritizeDegenNFT.js +0 -302
  120. package/dist/esm/abi/kyc/iSecuritizeKYCFactory.js +0 -295
  121. package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +0 -90
  122. package/dist/esm/plugins/pools-history/index.js +0 -2
  123. package/dist/esm/sdk/market/kyc/KYCRegistry.js +0 -253
  124. package/dist/esm/sdk/market/kyc/index.js +0 -3
  125. package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +0 -220
  126. package/dist/esm/sdk/market/kyc/securitize/constants.js +0 -4
  127. package/dist/esm/sdk/market/kyc/securitize/index.js +0 -3
  128. package/dist/esm/sdk/market/kyc/types.js +0 -9
  129. package/dist/esm/sdk/utils/viem/executeDelegatedMulticalls.js +0 -14
  130. package/dist/types/abi/kyc/iDSRegistryService.d.ts +0 -71
  131. package/dist/types/abi/kyc/iDSToken.d.ts +0 -67
  132. package/dist/types/abi/kyc/iKYCCompressor.d.ts +0 -228
  133. package/dist/types/abi/kyc/iKYCFactory.d.ts +0 -139
  134. package/dist/types/abi/kyc/iKYCUnderlying.d.ts +0 -548
  135. package/dist/types/abi/kyc/iSecuritizeDegenNFT.d.ts +0 -404
  136. package/dist/types/abi/kyc/iSecuritizeKYCFactory.d.ts +0 -376
  137. package/dist/types/plugins/pools-history/Pools7DAgoPlugin.d.ts +0 -20
  138. package/dist/types/plugins/pools-history/index.d.ts +0 -2
  139. package/dist/types/plugins/pools-history/types.d.ts +0 -9
  140. package/dist/types/sdk/market/kyc/KYCRegistry.d.ts +0 -52
  141. package/dist/types/sdk/market/kyc/index.d.ts +0 -3
  142. package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +0 -428
  143. package/dist/types/sdk/market/kyc/securitize/constants.d.ts +0 -1
  144. package/dist/types/sdk/market/kyc/securitize/index.d.ts +0 -3
  145. package/dist/types/sdk/market/kyc/securitize/types.d.ts +0 -127
  146. package/dist/types/sdk/market/kyc/types.d.ts +0 -170
  147. package/dist/types/sdk/utils/viem/executeDelegatedMulticalls.d.ts +0 -28
  148. /package/dist/cjs/plugins/{pools-history → apy}/package.json +0 -0
  149. /package/dist/cjs/plugins/{pools-history → apy}/types.js +0 -0
  150. /package/dist/esm/plugins/{pools-history → apy}/package.json +0 -0
  151. /package/dist/esm/plugins/{pools-history/types.js → apy/pool-apy-types.js} +0 -0
  152. /package/dist/esm/{sdk/market/kyc/securitize → plugins/apy}/types.js +0 -0
@@ -22,7 +22,6 @@ __export(AbstractCreditAccountsService_exports, {
22
22
  getWithdrawalCompressorAddress: () => getWithdrawalCompressorAddress
23
23
  });
24
24
  module.exports = __toCommonJS(AbstractCreditAccountsService_exports);
25
- var import_integrations_v3 = require("@gearbox-protocol/integrations-v3");
26
25
  var import_viem = require("viem");
27
26
  var import_generated = require("../../abi/310/generated.js");
28
27
  var import_creditAccountCompressor = require("../../abi/compressors/creditAccountCompressor.js");
@@ -30,12 +29,10 @@ var import_peripheryCompressor = require("../../abi/compressors/peripheryCompres
30
29
  var import_rewardsCompressor = require("../../abi/compressors/rewardsCompressor.js");
31
30
  var import_IWithdrawalCompressorV310 = require("../../abi/IWithdrawalCompressorV310.js");
32
31
  var import_iBaseRewardPool = require("../../abi/iBaseRewardPool.js");
33
- var import_iKYCFactory = require("../../abi/kyc/iKYCFactory.js");
34
32
  var import_base = require("../base/index.js");
35
33
  var import_chains = require("../chain/chains.js");
36
34
  var import_constants = require("../constants/index.js");
37
35
  var import_market = require("../market/index.js");
38
- var import_kyc = require("../market/kyc/index.js");
39
36
  var import_router = require("../router/index.js");
40
37
  var import_utils = require("../utils/index.js");
41
38
  var import_viem2 = require("../utils/viem/index.js");
@@ -79,40 +76,24 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
79
76
  } catch (_e) {
80
77
  return void 0;
81
78
  }
82
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
83
- raw.creditManager
84
- );
85
- const factory = marketSuite.kycFactory;
86
- let ca;
87
- let investor;
88
79
  if (raw.success) {
89
- ca = raw;
90
- investor = await factory?.getInvestor(raw.creditAccount, false);
91
- } else {
92
- const { txs: priceUpdateTxs } = await this.getUpdateForAccount(raw);
93
- [ca, investor] = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
94
- priceUpdates: priceUpdateTxs,
95
- contracts: [
96
- {
97
- abi: import_creditAccountCompressor.creditAccountCompressorAbi,
98
- address: this.#compressor,
99
- functionName: "getCreditAccountData",
100
- args: [account]
101
- },
102
- ...factory ? [
103
- {
104
- abi: import_iKYCFactory.iKYCFactoryAbi,
105
- address: factory.address,
106
- functionName: "getInvestor",
107
- args: [raw.creditAccount]
108
- }
109
- ] : []
110
- ],
111
- blockNumber,
112
- gas: this.sdk.gasLimit
113
- });
80
+ return raw;
114
81
  }
115
- return { ...ca, investor };
82
+ const { txs: priceUpdateTxs } = await this.getUpdateForAccount(raw);
83
+ const [cad] = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
84
+ priceUpdates: priceUpdateTxs,
85
+ contracts: [
86
+ {
87
+ abi: import_creditAccountCompressor.creditAccountCompressorAbi,
88
+ address: this.#compressor,
89
+ functionName: "getCreditAccountData",
90
+ args: [account]
91
+ }
92
+ ],
93
+ blockNumber,
94
+ gas: this.sdk.gasLimit
95
+ });
96
+ return cad;
116
97
  }
117
98
  /**
118
99
  * {@inheritDoc ICreditAccountsService.getCreditAccounts}
@@ -168,99 +149,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
168
149
  );
169
150
  return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
170
151
  }
171
- /**
172
- * {@inheritDoc ICreditAccountsService.getBorrowerCreditAccounts}
173
- **/
174
- async getBorrowerCreditAccounts(borrower, options, blockNumber) {
175
- const {
176
- creditManager,
177
- includeZeroDebt = false,
178
- maxHealthFactor = import_constants.MAX_UINT256,
179
- minHealthFactor = 0n,
180
- ignoreReservePrices = false
181
- } = options ?? {};
182
- const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
183
- ignoreReservePrices ? { main: true } : void 0
184
- );
185
- const investorDataList = await this.sdk.kyc.getInvestorData(borrower);
186
- const kycAccountAddresses = investorDataList.flatMap(
187
- (d) => d.creditAccounts.map((ca) => ca.creditAccount)
188
- );
189
- const cmFilter = creditManager ? {
190
- configurators: [],
191
- creditManagers: [creditManager],
192
- pools: [],
193
- underlying: import_constants.ADDRESS_0X0
194
- } : {
195
- configurators: this.marketConfigurators,
196
- creditManagers: [],
197
- pools: [],
198
- underlying: import_constants.ADDRESS_0X0
199
- };
200
- const permissiveFilter = {
201
- owner: borrower,
202
- includeZeroDebt: true,
203
- minHealthFactor: 0n,
204
- maxHealthFactor: import_constants.MAX_UINT256,
205
- reverting: false
206
- };
207
- const kycContracts = kycAccountAddresses.map(
208
- (account) => ({
209
- abi: import_creditAccountCompressor.creditAccountCompressorAbi,
210
- address: this.#compressor,
211
- functionName: "getCreditAccountData",
212
- args: [account]
213
- })
214
- );
215
- const getCreditAccountsContracts = [false, true].map(
216
- (reverting) => ({
217
- abi: import_creditAccountCompressor.creditAccountCompressorAbi,
218
- address: this.#compressor,
219
- functionName: "getCreditAccounts",
220
- args: [cmFilter, { ...permissiveFilter, reverting }, 0n]
221
- })
222
- );
223
- const allContracts = [...kycContracts, ...getCreditAccountsContracts];
224
- const results = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
225
- priceUpdates: priceUpdateTxs,
226
- contracts: allContracts,
227
- blockNumber,
228
- gas: this.sdk.gasLimit
229
- });
230
- const kycResults = results.slice(
231
- 0,
232
- kycAccountAddresses.length
233
- );
234
- const normalResults = results.slice(kycAccountAddresses.length);
235
- const seen = new import_utils.AddressSet();
236
- const allCAs = [];
237
- for (const ca of kycResults) {
238
- if (!seen.has(ca.creditAccount)) {
239
- seen.add(ca.creditAccount);
240
- allCAs.push({ ...ca, investor: borrower });
241
- }
242
- }
243
- for (const [accounts] of normalResults) {
244
- for (const ca of accounts) {
245
- if (!seen.has(ca.creditAccount)) {
246
- seen.add(ca.creditAccount);
247
- allCAs.push({ ...ca, investor: void 0 });
248
- }
249
- }
250
- }
251
- const filtered = allCAs.filter((ca) => {
252
- if (!includeZeroDebt && ca.debt === 0n) return false;
253
- if (ca.healthFactor < minHealthFactor) return false;
254
- if (ca.healthFactor > maxHealthFactor) return false;
255
- if (creditManager && !(0, import_utils.hexEq)(ca.creditManager, creditManager))
256
- return false;
257
- return true;
258
- });
259
- this.logger?.debug(
260
- `loaded ${allCAs.length} borrower credit accounts (${kycResults.length} KYC, ${filtered.length} after filter)`
261
- );
262
- return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
263
- }
264
152
  /**
265
153
  * {@inheritDoc ICreditAccountsService.getRewards}
266
154
  **/
@@ -470,13 +358,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
470
358
  closePath
471
359
  }) {
472
360
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
473
- await this.sdk.tokensMeta.loadTokenData(cm.underlying);
474
- const underlying = this.sdk.tokensMeta.mustGet(cm.underlying);
475
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
476
- throw new Error(
477
- "closeCreditAccount is not supported for KYC underlying credit accounts"
478
- );
479
- }
480
361
  const routerCloseResult = closePath || await this.sdk.routerFor(ca).findBestClosePath({
481
362
  creditAccount: ca,
482
363
  creditManager: cm.creditManager,
@@ -582,18 +463,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
582
463
  ],
583
464
  {}
584
465
  ) : [];
585
- const unwrapCalls = collateral && isDecrease ? await this.getKYCUnwrapCalls(
586
- collateral[0].balance,
587
- creditAccount.creditManager
588
- ) || [] : [];
589
- if (addCollateralCalls.length > 0 && unwrapCalls.length === 0 && collateral && collateral?.[0].token !== creditAccount.underlying) {
590
- throw new Error(
591
- "Can't use collateral other than underlying for non KYC market"
592
- );
593
- }
594
466
  const operationCalls = [
595
467
  ...addCollateralCalls,
596
- ...unwrapCalls,
597
468
  this.#prepareChangeDebt(creditAccount.creditFacade, change, isDecrease)
598
469
  ];
599
470
  const calls = await this.prependPriceUpdates(
@@ -801,30 +672,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
801
672
  const tx = await this.multicallTx(cm, creditAccount.creditAccount, calls);
802
673
  return { tx, calls, creditFacade: cm.creditFacade };
803
674
  }
804
- /**
805
- * {@inheritDoc ICreditAccountsService.getApprovalAddress}
806
- **/
807
- async getApprovalAddress(options) {
808
- const { creditManager } = options;
809
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
810
- const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
811
- const factory = marketSuite.kycFactory;
812
- if (factory) {
813
- return factory.getApprovalAddress(options);
814
- }
815
- return suite.creditManager.address;
816
- }
817
- /**
818
- * {@inheritDoc ICreditAccountsService.getOpenAccountRequirements}
819
- */
820
- async getOpenAccountRequirements(borrower, props) {
821
- const { creditManager } = props;
822
- const { kycFactory } = this.sdk.marketRegister.findByCreditManager(creditManager);
823
- if (!kycFactory) {
824
- return void 0;
825
- }
826
- return kycFactory.getOpenAccountRequirements(borrower);
827
- }
828
675
  /**
829
676
  * {@inheritDoc ICreditAccountsService.openCA}
830
677
  **/
@@ -959,131 +806,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
959
806
  return resp;
960
807
  }
961
808
  /**
962
- * Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
963
- * Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
964
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
965
- * @param amount - Number of vault shares (adapter tokens) to redeem
966
- * @param creditManager - Credit manager address
967
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
968
- */
969
- async getKYCUnwrapCalls(amount, creditManager) {
970
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
971
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
972
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
973
- return void 0;
974
- }
975
- const adapter = suite.creditManager.adapters.get(meta.addr);
976
- const adapterAddress = adapter?.address;
977
- if (!adapterAddress) {
978
- return void 0;
979
- }
980
- const mc = [
981
- {
982
- target: adapterAddress,
983
- callData: (0, import_viem.encodeFunctionData)({
984
- abi: import_integrations_v3.ierc4626AdapterAbi,
985
- functionName: "redeem",
986
- args: [amount, import_constants.ADDRESS_0X0, import_constants.ADDRESS_0X0]
987
- })
988
- }
989
- ];
990
- return mc;
991
- }
992
- /**
993
- * Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
994
- * Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
995
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
996
- * @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
997
- * @param creditManager - Credit manager address
998
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
999
- */
1000
- async getKYCWrapCalls(amount, creditManager) {
1001
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
1002
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
1003
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
1004
- return void 0;
1005
- }
1006
- const adapter = suite.creditManager.adapters.get(meta.addr);
1007
- const adapterAddress = adapter?.address;
1008
- if (!adapterAddress) {
1009
- return void 0;
1010
- }
1011
- const mc = [
1012
- {
1013
- target: adapterAddress,
1014
- callData: (0, import_viem.encodeFunctionData)({
1015
- abi: import_integrations_v3.ierc4626AdapterAbi,
1016
- functionName: "deposit",
1017
- args: [amount, import_constants.ADDRESS_0X0]
1018
- })
1019
- }
1020
- ];
1021
- return mc;
1022
- }
1023
- /**
1024
- * Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
1025
- * Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
1026
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
1027
- * @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
1028
- * @param creditManager - Credit manager address
1029
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
1030
- */
1031
- async getRedeemDiffCalls(amount, creditManager) {
1032
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
1033
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
1034
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
1035
- return void 0;
1036
- }
1037
- const adapter = suite.creditManager.adapters.get(meta.addr);
1038
- const adapterAddress = adapter?.address;
1039
- if (!adapterAddress) {
1040
- return void 0;
1041
- }
1042
- const mc = [
1043
- {
1044
- target: adapterAddress,
1045
- callData: (0, import_viem.encodeFunctionData)({
1046
- abi: import_integrations_v3.ierc4626AdapterAbi,
1047
- functionName: "redeemDiff",
1048
- args: [amount]
1049
- })
1050
- }
1051
- ];
1052
- return mc;
1053
- }
1054
- /**
1055
- * Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
1056
- * Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
1057
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
1058
- * @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
1059
- * @param creditManager - Credit manager address
1060
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
1061
- */
1062
- async getDepositDiffCalls(amount, creditManager) {
1063
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
1064
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
1065
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
1066
- return void 0;
1067
- }
1068
- const adapter = suite.creditManager.adapters.get(meta.addr);
1069
- const adapterAddress = adapter?.address;
1070
- if (!adapterAddress) {
1071
- return void 0;
1072
- }
1073
- const mc = [
1074
- {
1075
- target: adapterAddress,
1076
- callData: (0, import_viem.encodeFunctionData)({
1077
- abi: import_integrations_v3.ierc4626AdapterAbi,
1078
- functionName: "depositDiff",
1079
- args: [amount]
1080
- })
1081
- }
1082
- ];
1083
- return mc;
1084
- }
1085
- /**
1086
- * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
1087
809
  * {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
1088
810
  **/
1089
811
  async getOnDemandPriceUpdates(account, ignoreReservePrices) {
@@ -1341,17 +1063,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1341
1063
  * @returns
1342
1064
  */
1343
1065
  async openCreditAccountTx(suite, to, calls, referralCode) {
1344
- const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
1345
- const factory = marketSuite.kycFactory;
1346
- if (factory && (0, import_kyc.isKYCFactory)(factory, import_kyc.KYC_FACTORY_SECURITIZE)) {
1347
- const tokensToRegister = factory.dsTokens.map(
1348
- (t) => t.address
1349
- );
1350
- return factory.openCreditAccount(suite.creditManager.address, calls, {
1351
- tokensToRegister,
1352
- signaturesToCache: []
1353
- });
1354
- }
1355
1066
  return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
1356
1067
  }
1357
1068
  /**
@@ -1362,13 +1073,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1362
1073
  * @returns
1363
1074
  */
1364
1075
  async multicallTx(suite, creditAccount, calls) {
1365
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
1366
- suite.creditManager.address
1367
- );
1368
- const factory = marketSuite.kycFactory;
1369
- if (factory) {
1370
- return factory.multicall(creditAccount, calls);
1371
- }
1372
1076
  return suite.creditFacade.multicall(creditAccount, calls);
1373
1077
  }
1374
1078
  /**
@@ -1380,21 +1084,9 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1380
1084
  * @returns
1381
1085
  */
1382
1086
  async closeCreditAccountTx(suite, creditAccount, calls, operation) {
1383
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
1384
- suite.creditManager.address
1385
- );
1386
- const factory = marketSuite.kycFactory;
1387
1087
  if (operation === "close") {
1388
- if (factory) {
1389
- throw new Error(
1390
- "CloseOptions=close is not supported for KYC underlying credit accounts"
1391
- );
1392
- }
1393
1088
  return suite.creditFacade.closeCreditAccount(creditAccount, calls);
1394
1089
  }
1395
- if (factory) {
1396
- return factory.multicall(creditAccount, calls);
1397
- }
1398
1090
  return suite.creditFacade.multicall(creditAccount, calls);
1399
1091
  }
1400
1092
  }
@@ -113,23 +113,19 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
113
113
  creditAccount: ca,
114
114
  permits,
115
115
  to,
116
- tokensToClaim,
117
- calls: wrapCalls = []
116
+ tokensToClaim
118
117
  }) {
119
118
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
120
119
  const addCollateral = collateralAssets.filter((a) => a.balance > 0);
121
120
  const router = this.sdk.routerFor(ca);
122
- const unwrapCalls = await this.getRedeemDiffCalls(1n, ca.creditManager) ?? [];
123
121
  const claimPath = await router.findClaimAllRewards({
124
122
  tokensToClaim,
125
123
  creditAccount: ca
126
124
  });
127
125
  const operationCalls = [
128
126
  ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
129
- ...wrapCalls,
130
127
  ...this.prepareDisableQuotas(ca),
131
128
  ...this.prepareDecreaseDebt(ca),
132
- ...unwrapCalls,
133
129
  ...claimPath.calls,
134
130
  ...assetsToWithdraw.map(
135
131
  (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
@@ -161,12 +157,10 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
161
157
  tokensToClaim,
162
158
  creditAccount: ca
163
159
  });
164
- const wrapCalls = await this.getDepositDiffCalls(1n, ca.creditManager) ?? [];
165
160
  const addCollateral = collateralAssets.filter((a) => a.balance > 0);
166
161
  const operationCalls = [
167
162
  ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
168
163
  ...claimPath.calls,
169
- ...wrapCalls,
170
164
  ...assetsToWithdraw.map(
171
165
  (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
172
166
  )
@@ -21,6 +21,7 @@ __export(TokensMeta_exports, {
21
21
  TokensMeta: () => TokensMeta
22
22
  });
23
23
  module.exports = __toCommonJS(TokensMeta_exports);
24
+ var import_viem = require("viem");
24
25
  var import_iStateSerializer = require("../../abi/iStateSerializer.js");
25
26
  var import_iVersion = require("../../abi/iVersion.js");
26
27
  var import_utils = require("../utils/index.js");
@@ -80,14 +81,6 @@ class TokensMeta extends import_utils.AddressMap {
80
81
  }
81
82
  return !!t.contractType?.startsWith("PHANTOM_TOKEN::");
82
83
  }
83
- /**
84
- * Returns true if the token is a KYC underlying token, throws if the token data is not loaded
85
- * @param t
86
- * @returns
87
- */
88
- isKYCUnderlying(t) {
89
- return !!t.contractType?.startsWith("KYC_UNDERLYING::");
90
- }
91
84
  /**
92
85
  * Returns a map of all phantom tokens
93
86
  * Throws if token data is not loaded
@@ -101,19 +94,6 @@ class TokensMeta extends import_utils.AddressMap {
101
94
  }
102
95
  return result;
103
96
  }
104
- /**
105
- * Returns a map of all KYC underlying tokens
106
- * Throws if token data is not loaded
107
- */
108
- get kycUnderlyings() {
109
- const result = new import_utils.AddressMap();
110
- for (const [token, meta] of this.entries()) {
111
- if (this.isKYCUnderlying(meta)) {
112
- result.upsert(token, meta);
113
- }
114
- }
115
- return result;
116
- }
117
97
  formatBN(arg0, arg1, arg2) {
118
98
  const token = typeof arg0 === "object" ? arg0.token : arg0;
119
99
  const amount = typeof arg0 === "object" ? arg0.balance : arg1;
@@ -144,7 +124,7 @@ class TokensMeta extends import_utils.AddressMap {
144
124
  }
145
125
  /**
146
126
  * Loads token information about phantom tokens
147
- * In future other custom tokens types that do not have compressors might be handled here
127
+ * Other special tokens may be loaded here in the future
148
128
  *
149
129
  * @param tokens - tokens to load data for, defaults to all tokens
150
130
  */
@@ -173,19 +153,10 @@ class TokensMeta extends import_utils.AddressMap {
173
153
  batchSize: 0
174
154
  });
175
155
  this.#logger?.debug(`loaded ${resp.length} contract types`);
176
- const kycFactories = new import_utils.AddressSet();
177
156
  for (let i = 0; i < tokensToLoad.length; i++) {
178
- const meta = this.#overrideTokenMeta(
179
- tokensToLoad[i],
180
- resp[2 * i],
181
- resp[2 * i + 1]
182
- );
157
+ this.#overrideTokenMeta(tokensToLoad[i], resp[2 * i], resp[2 * i + 1]);
183
158
  this.#tokenDataLoaded.add(tokensToLoad[i]);
184
- if (this.isKYCUnderlying(meta)) {
185
- kycFactories.add(meta.kycFactory);
186
- }
187
159
  }
188
- this.#logger?.debug(`found ${kycFactories.size} KYC factories`);
189
160
  }
190
161
  #overrideTokenMeta(token, contractTypeResp, _serializeResp) {
191
162
  const meta = this.mustGet(token);
@@ -199,6 +170,46 @@ class TokensMeta extends import_utils.AddressMap {
199
170
  }
200
171
  return this.mustGet(token);
201
172
  }
173
+ async #loadWithoutCompressor(tokens_) {
174
+ if (tokens_.size === 0) {
175
+ return;
176
+ }
177
+ const tokens = Array.from(tokens_);
178
+ const resp = await this.#client.multicall({
179
+ contracts: tokens.flatMap(
180
+ (t) => [
181
+ {
182
+ address: t,
183
+ abi: import_viem.erc20Abi,
184
+ functionName: "symbol"
185
+ },
186
+ {
187
+ address: t,
188
+ abi: import_viem.erc20Abi,
189
+ functionName: "name"
190
+ },
191
+ {
192
+ address: t,
193
+ abi: import_viem.erc20Abi,
194
+ functionName: "decimals"
195
+ }
196
+ ]
197
+ ),
198
+ allowFailure: false,
199
+ batchSize: 0
200
+ });
201
+ this.#logger?.debug(
202
+ `loaded ${resp.length} basic metadata without compressor`
203
+ );
204
+ for (let i = 0; i < tokens.length; i++) {
205
+ this.upsert(tokens[i], {
206
+ addr: tokens[i],
207
+ symbol: resp[3 * i],
208
+ name: resp[3 * i + 1],
209
+ decimals: resp[3 * i + 2]
210
+ });
211
+ }
212
+ }
202
213
  }
203
214
  // Annotate the CommonJS export names for ESM import in node:
204
215
  0 && (module.exports = {
@@ -18,9 +18,6 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var token_types_exports = {};
20
20
  __export(token_types_exports, {
21
- KYC_ON_DEMAND_LP_MONOPOLIZED: () => KYC_ON_DEMAND_LP_MONOPOLIZED,
22
- KYC_UNDERLYING_DEFAULT: () => KYC_UNDERLYING_DEFAULT,
23
- KYC_UNDERLYING_ON_DEMAND: () => KYC_UNDERLYING_ON_DEMAND,
24
21
  PHANTOM_TOKEN_CONTRACT_TYPES: () => PHANTOM_TOKEN_CONTRACT_TYPES
25
22
  });
26
23
  module.exports = __toCommonJS(token_types_exports);
@@ -33,13 +30,7 @@ const PHANTOM_TOKEN_CONTRACT_TYPES = [
33
30
  "PHANTOM_TOKEN::STAKING_REWARDS",
34
31
  "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"
35
32
  ];
36
- const KYC_UNDERLYING_DEFAULT = "KYC_UNDERLYING::DEFAULT";
37
- const KYC_UNDERLYING_ON_DEMAND = "KYC_UNDERLYING::ON_DEMAND";
38
- const KYC_ON_DEMAND_LP_MONOPOLIZED = "ON_DEMAND_LP::MONOPOLIZED";
39
33
  // Annotate the CommonJS export names for ESM import in node:
40
34
  0 && (module.exports = {
41
- KYC_ON_DEMAND_LP_MONOPOLIZED,
42
- KYC_UNDERLYING_DEFAULT,
43
- KYC_UNDERLYING_ON_DEMAND,
44
35
  PHANTOM_TOKEN_CONTRACT_TYPES
45
36
  });