@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
@@ -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,
@@ -9,7 +8,6 @@ import { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompresso
9
8
  import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
10
9
  import { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompressorV310.js";
11
10
  import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
12
- import { iKYCFactoryAbi } from "../../abi/kyc/iKYCFactory.js";
13
11
  import { SDKConstruct } from "../base/index.js";
14
12
  import { chains } from "../chain/chains.js";
15
13
  import {
@@ -27,7 +25,7 @@ import {
27
25
  getRawPriceUpdates
28
26
  } from "../market/index.js";
29
27
  import { assetsMap } from "../router/index.js";
30
- import { AddressMap, AddressSet, hexEq } from "../utils/index.js";
28
+ import { AddressMap, AddressSet } from "../utils/index.js";
31
29
  import { simulateWithPriceUpdates } from "../utils/viem/index.js";
32
30
  import {
33
31
  extractPriceUpdates,
@@ -73,40 +71,24 @@ class AbstractCreditAccountService extends SDKConstruct {
73
71
  } catch (_e) {
74
72
  return void 0;
75
73
  }
76
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
77
- raw.creditManager
78
- );
79
- const factory = marketSuite.kycFactory;
80
- let ca;
81
- let investor;
82
74
  if (raw.success) {
83
- ca = raw;
84
- investor = await factory?.getInvestor(raw.creditAccount, false);
85
- } else {
86
- const { txs: priceUpdateTxs } = await this.getUpdateForAccount(raw);
87
- [ca, investor] = await simulateWithPriceUpdates(this.client, {
88
- priceUpdates: priceUpdateTxs,
89
- contracts: [
90
- {
91
- abi: creditAccountCompressorAbi,
92
- address: this.#compressor,
93
- functionName: "getCreditAccountData",
94
- args: [account]
95
- },
96
- ...factory ? [
97
- {
98
- abi: iKYCFactoryAbi,
99
- address: factory.address,
100
- functionName: "getInvestor",
101
- args: [raw.creditAccount]
102
- }
103
- ] : []
104
- ],
105
- blockNumber,
106
- gas: this.sdk.gasLimit
107
- });
75
+ return raw;
108
76
  }
109
- return { ...ca, investor };
77
+ const { txs: priceUpdateTxs } = await this.getUpdateForAccount(raw);
78
+ const [cad] = await simulateWithPriceUpdates(this.client, {
79
+ priceUpdates: priceUpdateTxs,
80
+ contracts: [
81
+ {
82
+ abi: creditAccountCompressorAbi,
83
+ address: this.#compressor,
84
+ functionName: "getCreditAccountData",
85
+ args: [account]
86
+ }
87
+ ],
88
+ blockNumber,
89
+ gas: this.sdk.gasLimit
90
+ });
91
+ return cad;
110
92
  }
111
93
  /**
112
94
  * {@inheritDoc ICreditAccountsService.getCreditAccounts}
@@ -162,99 +144,6 @@ class AbstractCreditAccountService extends SDKConstruct {
162
144
  );
163
145
  return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
164
146
  }
165
- /**
166
- * {@inheritDoc ICreditAccountsService.getBorrowerCreditAccounts}
167
- **/
168
- async getBorrowerCreditAccounts(borrower, options, blockNumber) {
169
- const {
170
- creditManager,
171
- includeZeroDebt = false,
172
- maxHealthFactor = MAX_UINT256,
173
- minHealthFactor = 0n,
174
- ignoreReservePrices = false
175
- } = options ?? {};
176
- const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
177
- ignoreReservePrices ? { main: true } : void 0
178
- );
179
- const investorDataList = await this.sdk.kyc.getInvestorData(borrower);
180
- const kycAccountAddresses = investorDataList.flatMap(
181
- (d) => d.creditAccounts.map((ca) => ca.creditAccount)
182
- );
183
- const cmFilter = creditManager ? {
184
- configurators: [],
185
- creditManagers: [creditManager],
186
- pools: [],
187
- underlying: ADDRESS_0X0
188
- } : {
189
- configurators: this.marketConfigurators,
190
- creditManagers: [],
191
- pools: [],
192
- underlying: ADDRESS_0X0
193
- };
194
- const permissiveFilter = {
195
- owner: borrower,
196
- includeZeroDebt: true,
197
- minHealthFactor: 0n,
198
- maxHealthFactor: MAX_UINT256,
199
- reverting: false
200
- };
201
- const kycContracts = kycAccountAddresses.map(
202
- (account) => ({
203
- abi: creditAccountCompressorAbi,
204
- address: this.#compressor,
205
- functionName: "getCreditAccountData",
206
- args: [account]
207
- })
208
- );
209
- const getCreditAccountsContracts = [false, true].map(
210
- (reverting) => ({
211
- abi: creditAccountCompressorAbi,
212
- address: this.#compressor,
213
- functionName: "getCreditAccounts",
214
- args: [cmFilter, { ...permissiveFilter, reverting }, 0n]
215
- })
216
- );
217
- const allContracts = [...kycContracts, ...getCreditAccountsContracts];
218
- const results = await simulateWithPriceUpdates(this.client, {
219
- priceUpdates: priceUpdateTxs,
220
- contracts: allContracts,
221
- blockNumber,
222
- gas: this.sdk.gasLimit
223
- });
224
- const kycResults = results.slice(
225
- 0,
226
- kycAccountAddresses.length
227
- );
228
- const normalResults = results.slice(kycAccountAddresses.length);
229
- const seen = new AddressSet();
230
- const allCAs = [];
231
- for (const ca of kycResults) {
232
- if (!seen.has(ca.creditAccount)) {
233
- seen.add(ca.creditAccount);
234
- allCAs.push({ ...ca, investor: borrower });
235
- }
236
- }
237
- for (const [accounts] of normalResults) {
238
- for (const ca of accounts) {
239
- if (!seen.has(ca.creditAccount)) {
240
- seen.add(ca.creditAccount);
241
- allCAs.push({ ...ca, investor: void 0 });
242
- }
243
- }
244
- }
245
- const filtered = allCAs.filter((ca) => {
246
- if (!includeZeroDebt && ca.debt === 0n) return false;
247
- if (ca.healthFactor < minHealthFactor) return false;
248
- if (ca.healthFactor > maxHealthFactor) return false;
249
- if (creditManager && !hexEq(ca.creditManager, creditManager))
250
- return false;
251
- return true;
252
- });
253
- this.logger?.debug(
254
- `loaded ${allCAs.length} borrower credit accounts (${kycResults.length} KYC, ${filtered.length} after filter)`
255
- );
256
- return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
257
- }
258
147
  /**
259
148
  * {@inheritDoc ICreditAccountsService.getRewards}
260
149
  **/
@@ -464,13 +353,6 @@ class AbstractCreditAccountService extends SDKConstruct {
464
353
  closePath
465
354
  }) {
466
355
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
467
- await this.sdk.tokensMeta.loadTokenData(cm.underlying);
468
- const underlying = this.sdk.tokensMeta.mustGet(cm.underlying);
469
- if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
470
- throw new Error(
471
- "closeCreditAccount is not supported for KYC underlying credit accounts"
472
- );
473
- }
474
356
  const routerCloseResult = closePath || await this.sdk.routerFor(ca).findBestClosePath({
475
357
  creditAccount: ca,
476
358
  creditManager: cm.creditManager,
@@ -576,18 +458,8 @@ class AbstractCreditAccountService extends SDKConstruct {
576
458
  ],
577
459
  {}
578
460
  ) : [];
579
- const unwrapCalls = collateral && isDecrease ? await this.getKYCUnwrapCalls(
580
- collateral[0].balance,
581
- creditAccount.creditManager
582
- ) || [] : [];
583
- if (addCollateralCalls.length > 0 && unwrapCalls.length === 0 && collateral && collateral?.[0].token !== creditAccount.underlying) {
584
- throw new Error(
585
- "Can't use collateral other than underlying for non KYC market"
586
- );
587
- }
588
461
  const operationCalls = [
589
462
  ...addCollateralCalls,
590
- ...unwrapCalls,
591
463
  this.#prepareChangeDebt(creditAccount.creditFacade, change, isDecrease)
592
464
  ];
593
465
  const calls = await this.prependPriceUpdates(
@@ -795,36 +667,6 @@ class AbstractCreditAccountService extends SDKConstruct {
795
667
  const tx = await this.multicallTx(cm, creditAccount.creditAccount, calls);
796
668
  return { tx, calls, creditFacade: cm.creditFacade };
797
669
  }
798
- /**
799
- * Returns address to which approval should be given on collateral token
800
- * It's credit manager for classical markets and special wallet for KYC markets
801
- * @param options - {@link GetApprovalAddressProps}
802
- * @returns
803
- **/
804
- async getApprovalAddress(options) {
805
- const { creditManager } = options;
806
- const suite = this.sdk.marketRegister.findCreditManager(creditManager);
807
- const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
808
- const factory = marketSuite.kycFactory;
809
- if (factory) {
810
- if ("creditAccount" in options) {
811
- return factory.getWallet(options.creditAccount);
812
- }
813
- return factory.precomputeWalletAddress(creditManager, options.borrower);
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
670
  /**
829
671
  * {@inheritDoc ICreditAccountsService.openCA}
830
672
  **/
@@ -959,131 +801,6 @@ class AbstractCreditAccountService extends SDKConstruct {
959
801
  return resp;
960
802
  }
961
803
  /**
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: encodeFunctionData({
984
- abi: ierc4626AdapterAbi,
985
- functionName: "redeem",
986
- args: [amount, ADDRESS_0X0, 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: encodeFunctionData({
1015
- abi: ierc4626AdapterAbi,
1016
- functionName: "deposit",
1017
- args: [amount, 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: encodeFunctionData({
1046
- abi: 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: encodeFunctionData({
1077
- abi: 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
804
  * {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
1088
805
  **/
1089
806
  async getOnDemandPriceUpdates(account, ignoreReservePrices) {
@@ -1341,19 +1058,6 @@ class AbstractCreditAccountService extends SDKConstruct {
1341
1058
  * @returns
1342
1059
  */
1343
1060
  async openCreditAccountTx(suite, to, calls, referralCode) {
1344
- const marketSuite = this.sdk.marketRegister.findByPool(suite.pool);
1345
- const factory = marketSuite.kycFactory;
1346
- if (factory) {
1347
- const tokensToRegister = factory.dsTokens.map(
1348
- (t) => t.address
1349
- );
1350
- return factory.openCreditAccount(
1351
- suite.creditManager.address,
1352
- calls,
1353
- tokensToRegister,
1354
- []
1355
- );
1356
- }
1357
1061
  return suite.creditFacade.openCreditAccount(to, calls, referralCode ?? 0n);
1358
1062
  }
1359
1063
  /**
@@ -1364,13 +1068,6 @@ class AbstractCreditAccountService extends SDKConstruct {
1364
1068
  * @returns
1365
1069
  */
1366
1070
  async multicallTx(suite, creditAccount, calls) {
1367
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
1368
- suite.creditManager.address
1369
- );
1370
- const factory = marketSuite.kycFactory;
1371
- if (factory) {
1372
- return factory.multicall(creditAccount, calls, [], []);
1373
- }
1374
1071
  return suite.creditFacade.multicall(creditAccount, calls);
1375
1072
  }
1376
1073
  /**
@@ -1382,21 +1079,9 @@ class AbstractCreditAccountService extends SDKConstruct {
1382
1079
  * @returns
1383
1080
  */
1384
1081
  async closeCreditAccountTx(suite, creditAccount, calls, operation) {
1385
- const marketSuite = this.sdk.marketRegister.findByCreditManager(
1386
- suite.creditManager.address
1387
- );
1388
- const factory = marketSuite.kycFactory;
1389
1082
  if (operation === "close") {
1390
- if (factory) {
1391
- throw new Error(
1392
- "CloseOptions=close is not supported for KYC underlying credit accounts"
1393
- );
1394
- }
1395
1083
  return suite.creditFacade.closeCreditAccount(creditAccount, calls);
1396
1084
  }
1397
- if (factory) {
1398
- return factory.multicall(creditAccount, calls, [], []);
1399
- }
1400
1085
  return suite.creditFacade.multicall(creditAccount, calls);
1401
1086
  }
1402
1087
  }
@@ -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
  )
@@ -1,3 +1,6 @@
1
+ import {
2
+ erc20Abi
3
+ } from "viem";
1
4
  import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
2
5
  import { iVersionAbi } from "../../abi/iVersion.js";
3
6
  import {
@@ -62,14 +65,6 @@ class TokensMeta extends AddressMap {
62
65
  }
63
66
  return !!t.contractType?.startsWith("PHANTOM_TOKEN::");
64
67
  }
65
- /**
66
- * Returns true if the token is a KYC underlying token, throws if the token data is not loaded
67
- * @param t
68
- * @returns
69
- */
70
- isKYCUnderlying(t) {
71
- return !!t.contractType?.startsWith("KYC_UNDERLYING::");
72
- }
73
68
  /**
74
69
  * Returns a map of all phantom tokens
75
70
  * Throws if token data is not loaded
@@ -83,19 +78,6 @@ class TokensMeta extends AddressMap {
83
78
  }
84
79
  return result;
85
80
  }
86
- /**
87
- * Returns a map of all KYC underlying tokens
88
- * Throws if token data is not loaded
89
- */
90
- get kycUnderlyings() {
91
- const result = new AddressMap();
92
- for (const [token, meta] of this.entries()) {
93
- if (this.isKYCUnderlying(meta)) {
94
- result.upsert(token, meta);
95
- }
96
- }
97
- return result;
98
- }
99
81
  formatBN(arg0, arg1, arg2) {
100
82
  const token = typeof arg0 === "object" ? arg0.token : arg0;
101
83
  const amount = typeof arg0 === "object" ? arg0.balance : arg1;
@@ -126,7 +108,7 @@ class TokensMeta extends AddressMap {
126
108
  }
127
109
  /**
128
110
  * Loads token information about phantom tokens
129
- * In future other custom tokens types that do not have compressors might be handled here
111
+ * Other special tokens may be loaded here in the future
130
112
  *
131
113
  * @param tokens - tokens to load data for, defaults to all tokens
132
114
  */
@@ -155,19 +137,10 @@ class TokensMeta extends AddressMap {
155
137
  batchSize: 0
156
138
  });
157
139
  this.#logger?.debug(`loaded ${resp.length} contract types`);
158
- const kycFactories = new AddressSet();
159
140
  for (let i = 0; i < tokensToLoad.length; i++) {
160
- const meta = this.#overrideTokenMeta(
161
- tokensToLoad[i],
162
- resp[2 * i],
163
- resp[2 * i + 1]
164
- );
141
+ this.#overrideTokenMeta(tokensToLoad[i], resp[2 * i], resp[2 * i + 1]);
165
142
  this.#tokenDataLoaded.add(tokensToLoad[i]);
166
- if (this.isKYCUnderlying(meta)) {
167
- kycFactories.add(meta.kycFactory);
168
- }
169
143
  }
170
- this.#logger?.debug(`found ${kycFactories.size} KYC factories`);
171
144
  }
172
145
  #overrideTokenMeta(token, contractTypeResp, _serializeResp) {
173
146
  const meta = this.mustGet(token);
@@ -181,6 +154,46 @@ class TokensMeta extends AddressMap {
181
154
  }
182
155
  return this.mustGet(token);
183
156
  }
157
+ async #loadWithoutCompressor(tokens_) {
158
+ if (tokens_.size === 0) {
159
+ return;
160
+ }
161
+ const tokens = Array.from(tokens_);
162
+ const resp = await this.#client.multicall({
163
+ contracts: tokens.flatMap(
164
+ (t) => [
165
+ {
166
+ address: t,
167
+ abi: erc20Abi,
168
+ functionName: "symbol"
169
+ },
170
+ {
171
+ address: t,
172
+ abi: erc20Abi,
173
+ functionName: "name"
174
+ },
175
+ {
176
+ address: t,
177
+ abi: erc20Abi,
178
+ functionName: "decimals"
179
+ }
180
+ ]
181
+ ),
182
+ allowFailure: false,
183
+ batchSize: 0
184
+ });
185
+ this.#logger?.debug(
186
+ `loaded ${resp.length} basic metadata without compressor`
187
+ );
188
+ for (let i = 0; i < tokens.length; i++) {
189
+ this.upsert(tokens[i], {
190
+ addr: tokens[i],
191
+ symbol: resp[3 * i],
192
+ name: resp[3 * i + 1],
193
+ decimals: resp[3 * i + 2]
194
+ });
195
+ }
196
+ }
184
197
  }
185
198
  export {
186
199
  TokensMeta
@@ -7,12 +7,6 @@ const PHANTOM_TOKEN_CONTRACT_TYPES = [
7
7
  "PHANTOM_TOKEN::STAKING_REWARDS",
8
8
  "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"
9
9
  ];
10
- const KYC_UNDERLYING_DEFAULT = "KYC_UNDERLYING::DEFAULT";
11
- const KYC_UNDERLYING_ON_DEMAND = "KYC_UNDERLYING::ON_DEMAND";
12
- const KYC_ON_DEMAND_LP_MONOPOLIZED = "ON_DEMAND_LP::MONOPOLIZED";
13
10
  export {
14
- KYC_ON_DEMAND_LP_MONOPOLIZED,
15
- KYC_UNDERLYING_DEFAULT,
16
- KYC_UNDERLYING_ON_DEMAND,
17
11
  PHANTOM_TOKEN_CONTRACT_TYPES
18
12
  };