@gearbox-protocol/sdk 13.6.0-kyc.6 → 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 -331
  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 -332
  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 -55
  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 -229
  112. package/dist/cjs/sdk/market/kyc/types.js +0 -29
  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 -205
  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 -5
  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 -420
  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 -107
  146. package/dist/types/sdk/market/kyc/types.d.ts +0 -136
  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,7 +29,6 @@ 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");
@@ -78,40 +76,24 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
78
76
  } catch (_e) {
79
77
  return void 0;
80
78
  }
81
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
82
- raw.creditManager
83
- );
84
- const factory = marketSuite.kycFactory;
85
- let ca;
86
- let investor;
87
79
  if (raw.success) {
88
- ca = raw;
89
- investor = await factory?.getInvestor(raw.creditAccount, false);
90
- } else {
91
- const { txs: priceUpdateTxs } = await this.getUpdateForAccount(raw);
92
- [ca, investor] = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
93
- priceUpdates: priceUpdateTxs,
94
- contracts: [
95
- {
96
- abi: import_creditAccountCompressor.creditAccountCompressorAbi,
97
- address: this.#compressor,
98
- functionName: "getCreditAccountData",
99
- args: [account]
100
- },
101
- ...factory ? [
102
- {
103
- abi: import_iKYCFactory.iKYCFactoryAbi,
104
- address: factory.address,
105
- functionName: "getInvestor",
106
- args: [raw.creditAccount]
107
- }
108
- ] : []
109
- ],
110
- blockNumber,
111
- gas: this.sdk.gasLimit
112
- });
80
+ return raw;
113
81
  }
114
- 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;
115
97
  }
116
98
  /**
117
99
  * {@inheritDoc ICreditAccountsService.getCreditAccounts}
@@ -167,99 +149,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
167
149
  );
168
150
  return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
169
151
  }
170
- /**
171
- * {@inheritDoc ICreditAccountsService.getBorrowerCreditAccounts}
172
- **/
173
- async getBorrowerCreditAccounts(borrower, options, blockNumber) {
174
- const {
175
- creditManager,
176
- includeZeroDebt = false,
177
- maxHealthFactor = import_constants.MAX_UINT256,
178
- minHealthFactor = 0n,
179
- ignoreReservePrices = false
180
- } = options ?? {};
181
- const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
182
- ignoreReservePrices ? { main: true } : void 0
183
- );
184
- const investorDataList = await this.sdk.kyc.getInvestorData(borrower);
185
- const kycAccountAddresses = investorDataList.flatMap(
186
- (d) => d.creditAccounts.map((ca) => ca.creditAccount)
187
- );
188
- const cmFilter = creditManager ? {
189
- configurators: [],
190
- creditManagers: [creditManager],
191
- pools: [],
192
- underlying: import_constants.ADDRESS_0X0
193
- } : {
194
- configurators: this.marketConfigurators,
195
- creditManagers: [],
196
- pools: [],
197
- underlying: import_constants.ADDRESS_0X0
198
- };
199
- const permissiveFilter = {
200
- owner: borrower,
201
- includeZeroDebt: true,
202
- minHealthFactor: 0n,
203
- maxHealthFactor: import_constants.MAX_UINT256,
204
- reverting: false
205
- };
206
- const kycContracts = kycAccountAddresses.map(
207
- (account) => ({
208
- abi: import_creditAccountCompressor.creditAccountCompressorAbi,
209
- address: this.#compressor,
210
- functionName: "getCreditAccountData",
211
- args: [account]
212
- })
213
- );
214
- const getCreditAccountsContracts = [false, true].map(
215
- (reverting) => ({
216
- abi: import_creditAccountCompressor.creditAccountCompressorAbi,
217
- address: this.#compressor,
218
- functionName: "getCreditAccounts",
219
- args: [cmFilter, { ...permissiveFilter, reverting }, 0n]
220
- })
221
- );
222
- const allContracts = [...kycContracts, ...getCreditAccountsContracts];
223
- const results = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
224
- priceUpdates: priceUpdateTxs,
225
- contracts: allContracts,
226
- blockNumber,
227
- gas: this.sdk.gasLimit
228
- });
229
- const kycResults = results.slice(
230
- 0,
231
- kycAccountAddresses.length
232
- );
233
- const normalResults = results.slice(kycAccountAddresses.length);
234
- const seen = new import_utils.AddressSet();
235
- const allCAs = [];
236
- for (const ca of kycResults) {
237
- if (!seen.has(ca.creditAccount)) {
238
- seen.add(ca.creditAccount);
239
- allCAs.push({ ...ca, investor: borrower });
240
- }
241
- }
242
- for (const [accounts] of normalResults) {
243
- for (const ca of accounts) {
244
- if (!seen.has(ca.creditAccount)) {
245
- seen.add(ca.creditAccount);
246
- allCAs.push({ ...ca, investor: void 0 });
247
- }
248
- }
249
- }
250
- const filtered = allCAs.filter((ca) => {
251
- if (!includeZeroDebt && ca.debt === 0n) return false;
252
- if (ca.healthFactor < minHealthFactor) return false;
253
- if (ca.healthFactor > maxHealthFactor) return false;
254
- if (creditManager && !(0, import_utils.hexEq)(ca.creditManager, creditManager))
255
- return false;
256
- return true;
257
- });
258
- this.logger?.debug(
259
- `loaded ${allCAs.length} borrower credit accounts (${kycResults.length} KYC, ${filtered.length} after filter)`
260
- );
261
- return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
262
- }
263
152
  /**
264
153
  * {@inheritDoc ICreditAccountsService.getRewards}
265
154
  **/
@@ -469,13 +358,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
469
358
  closePath
470
359
  }) {
471
360
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
472
- await this.sdk.tokensMeta.loadTokenData(cm.underlying);
473
- const underlying = this.sdk.tokensMeta.mustGet(cm.underlying);
474
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
475
- throw new Error(
476
- "closeCreditAccount is not supported for KYC underlying credit accounts"
477
- );
478
- }
479
361
  const routerCloseResult = closePath || await this.sdk.routerFor(ca).findBestClosePath({
480
362
  creditAccount: ca,
481
363
  creditManager: cm.creditManager,
@@ -581,18 +463,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
581
463
  ],
582
464
  {}
583
465
  ) : [];
584
- const unwrapCalls = collateral && isDecrease ? await this.getKYCUnwrapCalls(
585
- collateral[0].balance,
586
- creditAccount.creditManager
587
- ) || [] : [];
588
- if (addCollateralCalls.length > 0 && unwrapCalls.length === 0 && collateral && collateral?.[0].token !== creditAccount.underlying) {
589
- throw new Error(
590
- "Can't use collateral other than underlying for non KYC market"
591
- );
592
- }
593
466
  const operationCalls = [
594
467
  ...addCollateralCalls,
595
- ...unwrapCalls,
596
468
  this.#prepareChangeDebt(creditAccount.creditFacade, change, isDecrease)
597
469
  ];
598
470
  const calls = await this.prependPriceUpdates(
@@ -800,36 +672,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
800
672
  const tx = await this.multicallTx(cm, creditAccount.creditAccount, calls);
801
673
  return { tx, calls, creditFacade: cm.creditFacade };
802
674
  }
803
- /**
804
- * Returns address to which approval should be given on collateral token
805
- * It's credit manager for classical markets and special wallet for KYC markets
806
- * @param options - {@link GetApprovalAddressProps}
807
- * @returns
808
- **/
809
- async getApprovalAddress(options) {
810
- const { creditManager } = options;
811
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
812
- const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
813
- const factory = marketSuite.kycFactory;
814
- if (factory) {
815
- if ("creditAccount" in options) {
816
- return factory.getWallet(options.creditAccount);
817
- }
818
- return factory.precomputeWalletAddress(creditManager, options.borrower);
819
- }
820
- return suite.creditManager.address;
821
- }
822
- /**
823
- * {@inheritDoc ICreditAccountsService.getOpenAccountRequirements}
824
- */
825
- async getOpenAccountRequirements(borrower, props) {
826
- const { creditManager } = props;
827
- const { kycFactory } = this.sdk.marketRegister.findByCreditManager(creditManager);
828
- if (!kycFactory) {
829
- return void 0;
830
- }
831
- return kycFactory.getOpenAccountRequirements(borrower);
832
- }
833
675
  /**
834
676
  * {@inheritDoc ICreditAccountsService.openCA}
835
677
  **/
@@ -964,131 +806,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
964
806
  return resp;
965
807
  }
966
808
  /**
967
- * Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
968
- * Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
969
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
970
- * @param amount - Number of vault shares (adapter tokens) to redeem
971
- * @param creditManager - Credit manager address
972
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
973
- */
974
- async getKYCUnwrapCalls(amount, creditManager) {
975
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
976
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
977
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
978
- return void 0;
979
- }
980
- const adapter = suite.creditManager.adapters.get(meta.addr);
981
- const adapterAddress = adapter?.address;
982
- if (!adapterAddress) {
983
- return void 0;
984
- }
985
- const mc = [
986
- {
987
- target: adapterAddress,
988
- callData: (0, import_viem.encodeFunctionData)({
989
- abi: import_integrations_v3.ierc4626AdapterAbi,
990
- functionName: "redeem",
991
- args: [amount, import_constants.ADDRESS_0X0, import_constants.ADDRESS_0X0]
992
- })
993
- }
994
- ];
995
- return mc;
996
- }
997
- /**
998
- * Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
999
- * Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
1000
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
1001
- * @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
1002
- * @param creditManager - Credit manager address
1003
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
1004
- */
1005
- async getKYCWrapCalls(amount, creditManager) {
1006
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
1007
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
1008
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
1009
- return void 0;
1010
- }
1011
- const adapter = suite.creditManager.adapters.get(meta.addr);
1012
- const adapterAddress = adapter?.address;
1013
- if (!adapterAddress) {
1014
- return void 0;
1015
- }
1016
- const mc = [
1017
- {
1018
- target: adapterAddress,
1019
- callData: (0, import_viem.encodeFunctionData)({
1020
- abi: import_integrations_v3.ierc4626AdapterAbi,
1021
- functionName: "deposit",
1022
- args: [amount, import_constants.ADDRESS_0X0]
1023
- })
1024
- }
1025
- ];
1026
- return mc;
1027
- }
1028
- /**
1029
- * Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
1030
- * Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
1031
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
1032
- * @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
1033
- * @param creditManager - Credit manager address
1034
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
1035
- */
1036
- async getRedeemDiffCalls(amount, creditManager) {
1037
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
1038
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
1039
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
1040
- return void 0;
1041
- }
1042
- const adapter = suite.creditManager.adapters.get(meta.addr);
1043
- const adapterAddress = adapter?.address;
1044
- if (!adapterAddress) {
1045
- return void 0;
1046
- }
1047
- const mc = [
1048
- {
1049
- target: adapterAddress,
1050
- callData: (0, import_viem.encodeFunctionData)({
1051
- abi: import_integrations_v3.ierc4626AdapterAbi,
1052
- functionName: "redeemDiff",
1053
- args: [amount]
1054
- })
1055
- }
1056
- ];
1057
- return mc;
1058
- }
1059
- /**
1060
- * Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
1061
- * Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
1062
- * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
1063
- * @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
1064
- * @param creditManager - Credit manager address
1065
- * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
1066
- */
1067
- async getDepositDiffCalls(amount, creditManager) {
1068
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
1069
- const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
1070
- if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
1071
- return void 0;
1072
- }
1073
- const adapter = suite.creditManager.adapters.get(meta.addr);
1074
- const adapterAddress = adapter?.address;
1075
- if (!adapterAddress) {
1076
- return void 0;
1077
- }
1078
- const mc = [
1079
- {
1080
- target: adapterAddress,
1081
- callData: (0, import_viem.encodeFunctionData)({
1082
- abi: import_integrations_v3.ierc4626AdapterAbi,
1083
- functionName: "depositDiff",
1084
- args: [amount]
1085
- })
1086
- }
1087
- ];
1088
- return mc;
1089
- }
1090
- /**
1091
- * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
1092
809
  * {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
1093
810
  **/
1094
811
  async getOnDemandPriceUpdates(account, ignoreReservePrices) {
@@ -1346,19 +1063,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1346
1063
  * @returns
1347
1064
  */
1348
1065
  async openCreditAccountTx(suite, to, calls, referralCode) {
1349
- const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
1350
- const factory = marketSuite.kycFactory;
1351
- if (factory) {
1352
- const tokensToRegister = factory.dsTokens.map(
1353
- (t) => t.address
1354
- );
1355
- return factory.openCreditAccount(
1356
- suite.creditManager.address,
1357
- calls,
1358
- tokensToRegister,
1359
- []
1360
- );
1361
- }
1362
1066
  return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
1363
1067
  }
1364
1068
  /**
@@ -1369,13 +1073,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1369
1073
  * @returns
1370
1074
  */
1371
1075
  async multicallTx(suite, creditAccount, calls) {
1372
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
1373
- suite.creditManager.address
1374
- );
1375
- const factory = marketSuite.kycFactory;
1376
- if (factory) {
1377
- return factory.multicall(creditAccount, calls, [], []);
1378
- }
1379
1076
  return suite.creditFacade.multicall(creditAccount, calls);
1380
1077
  }
1381
1078
  /**
@@ -1387,21 +1084,9 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
1387
1084
  * @returns
1388
1085
  */
1389
1086
  async closeCreditAccountTx(suite, creditAccount, calls, operation) {
1390
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
1391
- suite.creditManager.address
1392
- );
1393
- const factory = marketSuite.kycFactory;
1394
1087
  if (operation === "close") {
1395
- if (factory) {
1396
- throw new Error(
1397
- "CloseOptions=close is not supported for KYC underlying credit accounts"
1398
- );
1399
- }
1400
1088
  return suite.creditFacade.closeCreditAccount(creditAccount, calls);
1401
1089
  }
1402
- if (factory) {
1403
- return factory.multicall(creditAccount, calls, [], []);
1404
- }
1405
1090
  return suite.creditFacade.multicall(creditAccount, calls);
1406
1091
  }
1407
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
  });