@gearbox-protocol/sdk 13.4.0-beta.3 → 13.5.0-kyc.1

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 (93) hide show
  1. package/dist/cjs/abi/310/iSecuritizeDegenNFT.js +263 -0
  2. package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +278 -0
  3. package/dist/cjs/{sdk/pools/PoolServiceV310.js → abi/iStateSerializer.js} +14 -8
  4. package/dist/cjs/dev/AccountOpener.js +45 -5
  5. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +411 -27
  6. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +16 -5
  7. package/dist/cjs/sdk/base/ChainContractsRegister.js +1 -1
  8. package/dist/cjs/sdk/base/TokensMeta.js +255 -32
  9. package/dist/cjs/sdk/base/index.js +2 -0
  10. package/dist/cjs/sdk/{constants/phantom-tokens.js → base/token-types.js} +9 -3
  11. package/dist/cjs/sdk/chain/chains.js +2 -1
  12. package/dist/cjs/sdk/constants/index.js +0 -2
  13. package/dist/cjs/sdk/market/MarketRegister.js +5 -2
  14. package/dist/cjs/sdk/market/MarketSuite.js +6 -0
  15. package/dist/cjs/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +110 -6
  16. package/dist/cjs/sdk/market/index.js +3 -1
  17. package/dist/cjs/sdk/market/pool/PoolSuite.js +3 -0
  18. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +17 -2
  19. package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +97 -0
  20. package/dist/cjs/sdk/market/pool/index.js +4 -0
  21. package/dist/cjs/sdk/pools/PoolService.js +391 -0
  22. package/dist/cjs/sdk/pools/index.js +2 -4
  23. package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
  24. package/dist/esm/abi/310/iSecuritizeDegenNFT.js +239 -0
  25. package/dist/esm/abi/310/iSecuritizeKYCFactory.js +254 -0
  26. package/dist/esm/abi/iStateSerializer.js +12 -0
  27. package/dist/esm/dev/AccountOpener.js +47 -6
  28. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +411 -27
  29. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +16 -5
  30. package/dist/esm/sdk/base/ChainContractsRegister.js +1 -1
  31. package/dist/esm/sdk/base/TokensMeta.js +261 -32
  32. package/dist/esm/sdk/base/index.js +1 -0
  33. package/dist/esm/sdk/{constants/phantom-tokens.js → base/token-types.js} +4 -0
  34. package/dist/esm/sdk/chain/chains.js +2 -1
  35. package/dist/esm/sdk/constants/index.js +0 -1
  36. package/dist/esm/sdk/market/MarketRegister.js +5 -2
  37. package/dist/esm/sdk/market/MarketSuite.js +6 -0
  38. package/dist/esm/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +109 -2
  39. package/dist/esm/sdk/market/index.js +1 -0
  40. package/dist/esm/sdk/market/pool/PoolSuite.js +3 -0
  41. package/dist/esm/sdk/market/pool/PoolV310Contract.js +17 -2
  42. package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +73 -0
  43. package/dist/esm/sdk/market/pool/index.js +2 -0
  44. package/dist/esm/sdk/pools/PoolService.js +371 -0
  45. package/dist/esm/sdk/pools/index.js +1 -2
  46. package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
  47. package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +324 -0
  48. package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +322 -0
  49. package/dist/types/abi/iStateSerializer.d.ts +11 -0
  50. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +115 -4
  51. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  52. package/dist/types/sdk/accounts/types.d.ts +107 -7
  53. package/dist/types/sdk/base/TokensMeta.d.ts +34 -21
  54. package/dist/types/sdk/base/index.d.ts +1 -0
  55. package/dist/types/sdk/base/token-types.d.ts +33 -0
  56. package/dist/types/sdk/base/types.d.ts +0 -7
  57. package/dist/types/sdk/chain/chains.d.ts +1 -1
  58. package/dist/types/sdk/constants/index.d.ts +0 -1
  59. package/dist/types/sdk/market/MarketRegister.d.ts +2 -2
  60. package/dist/types/sdk/market/MarketSuite.d.ts +3 -0
  61. package/dist/types/sdk/market/ZapperRegister.d.ts +17 -0
  62. package/dist/types/sdk/market/index.d.ts +1 -0
  63. package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -0
  64. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +6 -2
  65. package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +345 -0
  66. package/dist/types/sdk/market/pool/index.d.ts +2 -0
  67. package/dist/types/sdk/market/types.d.ts +10 -0
  68. package/dist/types/sdk/pools/PoolService.d.ts +14 -0
  69. package/dist/types/sdk/pools/index.d.ts +1 -2
  70. package/dist/types/sdk/pools/types.d.ts +85 -111
  71. package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
  72. package/package.json +1 -1
  73. package/dist/cjs/plugins/zappers/ZappersPlugin.js +0 -144
  74. package/dist/cjs/plugins/zappers/index.js +0 -26
  75. package/dist/cjs/plugins/zappers/package.json +0 -1
  76. package/dist/cjs/sdk/pools/AbstractPoolService.js +0 -143
  77. package/dist/cjs/sdk/pools/createPoolService.js +0 -35
  78. package/dist/esm/plugins/zappers/ZappersPlugin.js +0 -126
  79. package/dist/esm/plugins/zappers/index.js +0 -3
  80. package/dist/esm/plugins/zappers/package.json +0 -1
  81. package/dist/esm/sdk/pools/AbstractPoolService.js +0 -119
  82. package/dist/esm/sdk/pools/PoolServiceV310.js +0 -6
  83. package/dist/esm/sdk/pools/createPoolService.js +0 -11
  84. package/dist/types/plugins/zappers/ZappersPlugin.d.ts +0 -18
  85. package/dist/types/plugins/zappers/extraZappers.d.ts +0 -6
  86. package/dist/types/plugins/zappers/index.d.ts +0 -3
  87. package/dist/types/plugins/zappers/types.d.ts +0 -12
  88. package/dist/types/sdk/constants/phantom-tokens.d.ts +0 -2
  89. package/dist/types/sdk/pools/AbstractPoolService.d.ts +0 -21
  90. package/dist/types/sdk/pools/PoolServiceV310.d.ts +0 -4
  91. package/dist/types/sdk/pools/createPoolService.d.ts +0 -3
  92. /package/dist/cjs/{plugins/zappers → sdk/market}/types.js +0 -0
  93. /package/dist/esm/{plugins/zappers → sdk/market}/types.js +0 -0
@@ -2,10 +2,11 @@ import type { Address } from "viem";
2
2
  import type { CreditAccountData } from "../base/index.js";
3
3
  import { SDKConstruct } from "../base/index.js";
4
4
  import type { GearboxSDK } from "../GearboxSDK.js";
5
+ import type { CreditSuite, MarketSuite } from "../market/index.js";
5
6
  import { type PriceUpdate, type UpdatePriceFeedsResult } from "../market/index.js";
6
7
  import { type Asset, type RouterCASlice } from "../router/index.js";
7
- import type { MultiCall, RawTx } from "../types/index.js";
8
- import type { AccountToCheck, AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, CreditAccountTokensSlice, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
8
+ import type { IPriceUpdateTx, MultiCall, RawTx } from "../types/index.js";
9
+ import type { AccountToCheck, AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CloseOptions, CreditAccountDataWithInvestor, CreditAccountOperationResult, CreditAccountTokensSlice, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
9
10
  /**
10
11
  * Options for configuring the credit account service.
11
12
  **/
@@ -32,10 +33,42 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
32
33
  * {@inheritDoc ICreditAccountsService.getCreditAccountData}
33
34
  **/
34
35
  getCreditAccountData(account: Address, blockNumber?: bigint): Promise<CreditAccountData | undefined>;
36
+ /**
37
+ * Returns credit account data for a single account with the investor address resolved.
38
+ * Loads CA via getCreditAccountData; for KYC underlyings fetches the investor from the KYC factory's getInvestor(creditAccount), otherwise uses the account owner.
39
+ * @param account - Credit account address
40
+ * @param blockNumber - Optional block number for the read
41
+ * @returns CreditAccountDataWithInvestor (CA data + investor address), or undefined if the account is not found
42
+ */
43
+ getCreditAccountDataWithInvestor(account: Address, blockNumber?: bigint): Promise<CreditAccountDataWithInvestor | undefined>;
35
44
  /**
36
45
  * {@inheritDoc ICreditAccountsService.getCreditAccounts}
37
46
  **/
38
47
  getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountData>>;
48
+ /**
49
+ * Returns all credit accounts matching the filter, with investor set on each item.
50
+ * Delegates to getCreditAccounts; when options.owner is set, also loads KYC credit accounts for that owner and merges them into the list. Result is sorted by health factor ascending.
51
+ * @param options - Filter options (owner, creditManager, health factor, etc.)
52
+ * @param blockNumber - Optional block number for the read
53
+ * @returns Array of credit accounts (with investor field), sorted by health factor ascending
54
+ */
55
+ getCreditAccountsWithInvestor(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountDataWithInvestor>>;
56
+ protected getKYCCreditAccountsOfOwner(owner: Address, priceUpdateTxs: IPriceUpdateTx<{
57
+ priceFeed: `0x${string}`;
58
+ timestamp: number;
59
+ }>[], blockNumber?: bigint): Promise<Array<CreditAccountDataWithInvestor>>;
60
+ /**
61
+ * Loads credit account data for the given addresses using simulateWithPriceUpdates.
62
+ * Applies the provided price update txs before reading, so returned data is consistent with up-to-date prices.
63
+ * @param accounts - Credit account addresses to load
64
+ * @param priceUpdateTxs - Price feed update txs to simulate before the read (e.g. from generatePriceFeedsUpdateTxs)
65
+ * @param blockNumber - Optional block number for the read
66
+ * @returns Array of CreditAccountData in the same order as accounts (throws if any getCreditAccountData call reverts)
67
+ */
68
+ loadSpecifiedAccounts(accounts: Address[], priceUpdateTxs: IPriceUpdateTx<{
69
+ priceFeed: `0x${string}`;
70
+ timestamp: number;
71
+ }>[], blockNumber?: bigint): Promise<Array<CreditAccountData>>;
39
72
  /**
40
73
  * {@inheritDoc ICreditAccountsService.getRewards}
41
74
  **/
@@ -69,7 +102,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
69
102
  /**
70
103
  * {@inheritDoc ICreditAccountsService.changeDebt}
71
104
  **/
72
- changeDebt({ creditAccount, amount, addCollateral, }: ChangeDeptProps): Promise<CreditAccountOperationResult>;
105
+ changeDebt({ creditAccount, amount, collateral, }: ChangeDeptProps): Promise<CreditAccountOperationResult>;
73
106
  /**
74
107
  * {@inheritDoc ICreditAccountsService.executeSwap}
75
108
  **/
@@ -90,10 +123,17 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
90
123
  * {@inheritDoc ICreditAccountsService.claimDelayed}
91
124
  **/
92
125
  claimDelayed({ creditAccount, minQuota, averageQuota, claimableNow, }: ClaimDelayedProps): Promise<CreditAccountOperationResult>;
126
+ /**
127
+ * Returns address to which approval should be given on collateral token
128
+ * It's credit manager for classical markets and special wallet for KYC markets
129
+ * @param options - {@link GetApprovalAddressProps}
130
+ * @returns
131
+ **/
132
+ getApprovalAddress(options: GetApprovalAddressProps): Promise<Address>;
93
133
  /**
94
134
  * {@inheritDoc ICreditAccountsService.openCA}
95
135
  **/
96
- openCA({ ethAmount, creditManager, collateral, permits, debt, withdrawDebt, referralCode, to, calls: openPathCalls, minQuota, averageQuota, }: OpenCAProps): Promise<CreditAccountOperationResult>;
136
+ openCA(props: OpenCAProps): Promise<CreditAccountOperationResult>;
97
137
  /**
98
138
  * {@inheritDoc ICreditAccountsService.getBorrowRate}
99
139
  **/
@@ -103,6 +143,43 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
103
143
  **/
104
144
  getOptimalHFForPartialLiquidation(ca: CreditAccountData): bigint;
105
145
  /**
146
+ * Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
147
+ * Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
148
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
149
+ * @param amount - Number of vault shares (adapter tokens) to redeem
150
+ * @param creditManager - Credit manager address
151
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
152
+ */
153
+ getKYCUnwrapCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
154
+ /**
155
+ * Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
156
+ * Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
157
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
158
+ * @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
159
+ * @param creditManager - Credit manager address
160
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
161
+ */
162
+ getKYCWrapCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
163
+ /**
164
+ * Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
165
+ * Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
166
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
167
+ * @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
168
+ * @param creditManager - Credit manager address
169
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
170
+ */
171
+ getRedeemDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
172
+ /**
173
+ * Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
174
+ * Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
175
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
176
+ * @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
177
+ * @param creditManager - Credit manager address
178
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
179
+ */
180
+ getDepositDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
181
+ /**
182
+ * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
106
183
  * {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
107
184
  **/
108
185
  getOnDemandPriceUpdates(account: CreditAccountTokensSlice, ignoreReservePrices?: boolean): Promise<PriceUpdate[]>;
@@ -157,4 +234,38 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
157
234
  private get marketConfigurators();
158
235
  private get rewardCompressor();
159
236
  private get peripheryCompressor();
237
+ /**
238
+ * Wrapper that selects between credit facade and KYC factory
239
+ * @param suite
240
+ * @param to
241
+ * @param calls
242
+ * @param referralCode
243
+ * @returns
244
+ */
245
+ protected openCreditAccountTx(suite: CreditSuite, to: Address, calls: MultiCall[], referralCode?: bigint): Promise<RawTx>;
246
+ /**
247
+ * Wrapper that selects between credit facade and KYC factory
248
+ * @param suite
249
+ * @param creditAccount
250
+ * @param calls
251
+ * @returns
252
+ */
253
+ protected multicallTx(suite: CreditSuite, creditAccount: Address, calls: MultiCall[]): Promise<RawTx>;
254
+ /**
255
+ * Wrapper that selects between credit facade and KYC factory
256
+ * @param suite
257
+ * @param creditAccount
258
+ * @param calls
259
+ * @param operation
260
+ * @returns
261
+ */
262
+ protected closeCreditAccountTx(suite: CreditSuite, creditAccount: Address, calls: MultiCall[], operation: CloseOptions): Promise<RawTx>;
263
+ /**
264
+ * Returns all KYC credit account addresses for an investor across the given market suites.
265
+ * Resolves KYC factory per suite, then multicalls each factory's getCreditAccounts(investor).
266
+ * @param investor - Owner address to query
267
+ * @param suites - Market suites (KYC factories are resolved for each; undefined entries are skipped)
268
+ * @returns Flat array of credit account addresses from all KYC markets
269
+ */
270
+ protected getKYCCaOfInvestor(investor: Address, suites: Array<MarketSuite | undefined>): Promise<`0x${string}`[]>;
160
271
  }
@@ -21,7 +21,7 @@ export declare class CreditAccountServiceV310 extends AbstractCreditAccountServi
21
21
  /**
22
22
  * {@inheritDoc ICreditAccountsService.repayCreditAccount}
23
23
  */
24
- repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, tokensToClaim, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
24
+ repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, tokensToClaim, calls: wrapCalls, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
25
25
  /**
26
26
  * {@inheritDoc ICreditAccountsService.repayAndLiquidateCreditAccount}
27
27
  */
@@ -5,7 +5,7 @@ import type { ConnectedBotData, Construct, CreditAccountData } from "../base/ind
5
5
  import type { GearboxSDK } from "../GearboxSDK.js";
6
6
  import type { CreditSuite, PriceUpdate } from "../market/index.js";
7
7
  import type { Asset, RouterCASlice, RouterCloseResult } from "../router/index.js";
8
- import type { MultiCall, RawTx } from "../types/index.js";
8
+ import type { IPriceUpdateTx, MultiCall, RawTx } from "../types/index.js";
9
9
  /**
10
10
  * @internal
11
11
  * Arguments tuple for the credit account compressor's `getCreditAccounts` view method.
@@ -182,6 +182,10 @@ export interface CloseCreditAccountProps {
182
182
  closePath?: RouterCloseResult;
183
183
  }
184
184
  export interface RepayCreditAccountProps extends RepayAndLiquidateCreditAccountProps {
185
+ /**
186
+ * Swap calls for repay
187
+ */
188
+ calls?: Array<MultiCall>;
185
189
  /**
186
190
  * close or zeroDebt
187
191
  */
@@ -389,8 +393,9 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
389
393
  /**
390
394
  * Flag to withdraw debt to wallet after opening credit account;
391
395
  * used for borrowing functionality
396
+ * If true, will withdraw underlying token, otherwise will withdraw specified token
392
397
  */
393
- withdrawDebt?: boolean;
398
+ withdrawToken?: boolean | Address;
394
399
  /**
395
400
  * Permits of collateral tokens (in any permittable token is present) {@link PermitResult}
396
401
  */
@@ -400,10 +405,19 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
400
405
  * Used for trading and strategy functionality
401
406
  */
402
407
  calls: Array<MultiCall>;
408
+ /**
409
+ * Slot for optional call to execute after main tx.
410
+ * For example: add bots
411
+ */
412
+ callsAfter?: Array<MultiCall>;
403
413
  /**
404
414
  * Address of credit manager to open credit account on
405
415
  */
406
416
  creditManager: Address;
417
+ /**
418
+ * Optional address of credit account to reopen
419
+ */
420
+ reopenCreditAccount?: Address;
407
421
  /**
408
422
  * Wallet address to transfer credit account to
409
423
  */
@@ -426,9 +440,13 @@ export interface ChangeDeptProps {
426
440
  */
427
441
  amount: bigint;
428
442
  /**
429
- * If true, will add collateral to the credit account
443
+ * Assets to add as collateral
430
444
  */
431
- addCollateral: boolean;
445
+ collateral?: [Asset];
446
+ /**
447
+ * Assets to wrap
448
+ */
449
+ wrapAsset?: [Asset];
432
450
  }
433
451
  export interface FullyLiquidateProps {
434
452
  /**
@@ -604,6 +622,19 @@ export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotas
604
622
  */
605
623
  creditAccount: RouterCASlice;
606
624
  }
625
+ /**
626
+ * Options to get approval address for collateral token
627
+ */
628
+ export type GetApprovalAddressProps = {
629
+ creditManager: Address;
630
+ borrower: Address;
631
+ } | {
632
+ creditManager: Address;
633
+ creditAccount: Address;
634
+ };
635
+ export type CreditAccountDataWithInvestor = CreditAccountData & {
636
+ investor: Address;
637
+ };
607
638
  export interface ICreditAccountsService extends Construct {
608
639
  sdk: GearboxSDK;
609
640
  /**
@@ -614,15 +645,41 @@ export interface ICreditAccountsService extends Construct {
614
645
  * @returns
615
646
  */
616
647
  getCreditAccountData(account: Address, blockNumber?: bigint): Promise<CreditAccountData | undefined>;
648
+ /**
649
+ * Returns credit account data for a single account with the investor address resolved (from KYC factory when applicable).
650
+ * @param account - Credit account address
651
+ * @param blockNumber - Optional block number for the read
652
+ * @returns CreditAccountDataWithInvestor, or undefined if the account is not found
653
+ */
654
+ getCreditAccountDataWithInvestor(account: Address, blockNumber?: bigint): Promise<CreditAccountDataWithInvestor | undefined>;
617
655
  /**
618
656
  * Methods to get all credit accounts with some optional filtering
619
657
  * Performs all necessary price feed updates under the hood
620
658
  *
621
659
  * @param options
622
660
  * @param blockNumber
623
- * @returns returned credit accounts are sorted by health factor in ascending order
661
+ * @param priceUpdate - Optional pre-computed price feed update (e.g. from generatePriceFeedsUpdateTxs)
662
+ * @returns Credit accounts sorted by health factor ascending
624
663
  */
625
664
  getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountData>>;
665
+ /**
666
+ * Returns all credit accounts matching the filter with investor set on each; when options.owner is set, includes KYC CAs for that owner.
667
+ * @param options - Filter options (owner, creditManager, health factor, etc.)
668
+ * @param blockNumber - Optional block number for the read
669
+ * @returns Credit accounts (with investor) sorted by health factor ascending
670
+ */
671
+ getCreditAccountsWithInvestor(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountDataWithInvestor>>;
672
+ /**
673
+ * Loads credit account data for the given addresses using simulateWithPriceUpdates (with price updates applied before the read).
674
+ * @param accounts - Credit account addresses to load
675
+ * @param priceUpdateTxs - Price feed update txs to simulate before the read (e.g. from generatePriceFeedsUpdateTxs)
676
+ * @param blockNumber - Optional block number for the read
677
+ * @returns Array of CreditAccountData in the same order as accounts
678
+ */
679
+ loadSpecifiedAccounts(accounts: Address[], priceUpdateTxs: IPriceUpdateTx<{
680
+ priceFeed: `0x${string}`;
681
+ timestamp: number;
682
+ }>[], blockNumber?: bigint): Promise<Array<CreditAccountData>>;
626
683
  /**
627
684
  * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards).
628
685
  * Associates rewards by adapter + stakedPhantomToken.
@@ -651,9 +708,9 @@ export interface ICreditAccountsService extends Construct {
651
708
  /**
652
709
  * Generates transaction to liquidate credit account
653
710
  * @param props - {@link FullyLiquidateProps}
654
- * @returns
711
+ * @returns Transaction data and optional loss policy data
655
712
  */
656
- fullyLiquidate(props: FullyLiquidateProps): Promise<CloseCreditAccountResult>;
713
+ fullyLiquidate(props: FullyLiquidateProps): Promise<FullyLiquidateResult>;
657
714
  /**
658
715
  * Closes credit account or closes credit account and keeps it open with zero debt.
659
716
  * - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
@@ -716,6 +773,13 @@ export interface ICreditAccountsService extends Construct {
716
773
  * @returns
717
774
  */
718
775
  claimDelayed(props: ClaimDelayedProps): Promise<CreditAccountOperationResult>;
776
+ /**
777
+ * Returns address to which approval should be given on collateral token
778
+ * It's credit manager for classical markets and special wallet for KYC markets
779
+ * @param props - {@link GetApprovalAddressProps}
780
+ * @returns
781
+ */
782
+ getApprovalAddress(props: GetApprovalAddressProps): Promise<Address>;
719
783
  /**
720
784
  * Executes swap specified by given calls, update quotas of affected tokens
721
785
  * - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
@@ -771,6 +835,42 @@ export interface ICreditAccountsService extends Construct {
771
835
  botMulticall(creditAccount: RouterCASlice, calls: Array<MultiCall>, options?: {
772
836
  ignoreReservePrices?: boolean;
773
837
  }): Promise<RawTx>;
838
+ /**
839
+ * Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
840
+ * Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
841
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
842
+ * @param amount - Number of vault shares (adapter tokens) to redeem
843
+ * @param creditManager - Credit manager address
844
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
845
+ */
846
+ getKYCUnwrapCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
847
+ /**
848
+ * Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
849
+ * Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
850
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
851
+ * @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
852
+ * @param creditManager - Credit manager address
853
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
854
+ */
855
+ getKYCWrapCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
856
+ /**
857
+ * Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
858
+ * Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
859
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
860
+ * @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
861
+ * @param creditManager - Credit manager address
862
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
863
+ */
864
+ getRedeemDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
865
+ /**
866
+ * Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
867
+ * Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
868
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
869
+ * @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
870
+ * @param creditManager - Credit manager address
871
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
872
+ */
873
+ getDepositDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
774
874
  /**
775
875
  * Withdraws a single collateral from credit account to wallet to and updates quotas;
776
876
  * technically can withdraw several tokens at once
@@ -1,8 +1,8 @@
1
- import type { Address, Chain, PublicClient, Transport } from "viem";
2
- import type { PhantomTokenContractType } from "../constants/index.js";
1
+ import { type Address, type Chain, type PublicClient, type Transport } from "viem";
3
2
  import type { Asset } from "../router/index.js";
3
+ import type { ILogger } from "../types/logger.js";
4
4
  import { AddressMap } from "../utils/index.js";
5
- import type { TokenMetaData } from "./types.js";
5
+ import { type DSTokenMeta, type KYCTokenMeta, type PhantomTokenMeta, type TokenMetaData } from "./token-types.js";
6
6
  /**
7
7
  * Options for {@link TokensMeta.formatBN}.
8
8
  **/
@@ -16,15 +16,6 @@ export interface FormatBNOptions {
16
16
  **/
17
17
  symbol?: boolean;
18
18
  }
19
- /**
20
- * Token metadata enriched with some attributes specific to certain classes of tokens
21
- **/
22
- export interface TokenMetaDataExtended extends TokenMetaData {
23
- /**
24
- * Classification of the phantom token, or `undefined` for normal tokens.
25
- **/
26
- phantomTokenType?: PhantomTokenContractType;
27
- }
28
19
  /**
29
20
  * Registry of token metadata (symbol, decimals, phantom type) keyed by address.
30
21
  *
@@ -33,13 +24,14 @@ export interface TokenMetaDataExtended extends TokenMetaData {
33
24
  *
34
25
  * Provides methods to lazy-load information about certain classes of tokens (e.g. phantom tokens)
35
26
  */
36
- export declare class TokensMeta extends AddressMap<TokenMetaDataExtended> {
27
+ export declare class TokensMeta extends AddressMap<TokenMetaData> {
37
28
  #private;
38
- constructor(client: PublicClient<Transport, Chain>);
29
+ constructor(client: PublicClient<Transport, Chain>, logger?: ILogger);
39
30
  /**
40
31
  * Clears all token metadata
41
32
  **/
42
33
  reset(): void;
34
+ upsert(address: string, value: TokenMetaData | undefined): void;
43
35
  /**
44
36
  * Returns the symbol string for a token.
45
37
  * @param token - Token address.
@@ -53,15 +45,34 @@ export declare class TokensMeta extends AddressMap<TokenMetaDataExtended> {
53
45
  */
54
46
  decimals(token: Address): number;
55
47
  /**
56
- * Returns the phantom token type for a given token, or undefined for normal tokens
57
- * Throws if the phantom token data is not loaded
48
+ * Returns true if the token is a phantom token, throws if the token data is not loaded
49
+ * @param t
50
+ * @returns
51
+ */
52
+ isPhantomToken(t: TokenMetaData): t is PhantomTokenMeta;
53
+ /**
54
+ * Returns true if the token is a KYC underlying token, throws if the token data is not loaded
55
+ * @param t
56
+ * @returns
57
+ */
58
+ isKYCUnderlying(t: TokenMetaData): t is KYCTokenMeta;
59
+ /**
60
+ * Returns true if the token is a DSToken, throws if the token data is not loaded
61
+ * @param t
62
+ * @returns
58
63
  */
59
- phantomTokenType(token: Address): PhantomTokenContractType | undefined;
64
+ isDSToken(t: TokenMetaData): t is DSTokenMeta;
60
65
  /**
61
66
  * Returns a map of all phantom tokens
62
- * Throws if the phantom token data is not loaded
67
+ * Throws if token data is not loaded
63
68
  */
64
- get phantomTokens(): AddressMap<TokenMetaDataExtended>;
69
+ get phantomTokens(): AddressMap<PhantomTokenMeta>;
70
+ /**
71
+ * Returns a map of all KYC underlying tokens
72
+ * Throws if token data is not loaded
73
+ */
74
+ get kycUnderlyings(): AddressMap<KYCTokenMeta>;
75
+ get dsTokens(): AddressMap<DSTokenMeta>;
65
76
  /**
66
77
  * Formats a raw token amount into a human-readable decimal string,
67
78
  * dividing by `10^decimals` for the token.
@@ -91,7 +102,9 @@ export declare class TokensMeta extends AddressMap<TokenMetaDataExtended> {
91
102
  */
92
103
  mustFindBySymbol(symbol: string): TokenMetaData;
93
104
  /**
94
- * Loads phantom token data for all known tokens from chain
105
+ * Loads token information about phantom tokens, KYC underlying tokens and DSTokens
106
+ *
107
+ * @param tokens - tokens to load data for, defaults to all tokens
95
108
  */
96
- loadPhantomTokens(): Promise<void>;
109
+ loadTokenData(...tokens: Address[]): Promise<void>;
97
110
  }
@@ -5,4 +5,5 @@ export * from "./errors.js";
5
5
  export * from "./PlaceholderContract.js";
6
6
  export * from "./SDKConstruct.js";
7
7
  export * from "./TokensMeta.js";
8
+ export * from "./token-types.js";
8
9
  export * from "./types.js";
@@ -0,0 +1,33 @@
1
+ import type { Address } from "viem";
2
+ import type { MarketData, Unarray } from "./types.js";
3
+ type TokenData = Unarray<MarketData["tokens"]>;
4
+ export declare const PHANTOM_TOKEN_CONTRACT_TYPES: readonly ["PHANTOM_TOKEN::CONVEX", "PHANTOM_TOKEN::INFINIFI_UNWIND", "PHANTOM_TOKEN::INFRARED", "PHANTOM_TOKEN::MELLOW_WITHDRAWAL", "PHANTOM_TOKEN::MIDAS_REDEMPTION", "PHANTOM_TOKEN::STAKING_REWARDS", "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"];
5
+ export declare const KYC_UNDERLYING_DEFAULT = "KYC_UNDERLYING::DEFAULT";
6
+ export declare const KYC_UNDERLYING_ON_DEMAND = "KYC_UNDERLYING::ON_DEMAND";
7
+ export type KYCUnderlyingContractType = typeof KYC_UNDERLYING_DEFAULT | typeof KYC_UNDERLYING_ON_DEMAND;
8
+ export type PhantomTokenContractType = (typeof PHANTOM_TOKEN_CONTRACT_TYPES)[number];
9
+ export type SimpleTokenMeta = TokenData & {
10
+ isDSToken?: boolean;
11
+ contractType?: string;
12
+ };
13
+ export type PhantomTokenMeta = SimpleTokenMeta & {
14
+ contractType: PhantomTokenContractType;
15
+ };
16
+ export type KYCDefaultTokenMeta = SimpleTokenMeta & {
17
+ contractType: typeof KYC_UNDERLYING_DEFAULT;
18
+ kycFactory: Address;
19
+ asset: Address;
20
+ };
21
+ export type KYCOnDemandTokenMeta = SimpleTokenMeta & {
22
+ contractType: typeof KYC_UNDERLYING_ON_DEMAND;
23
+ kycFactory: Address;
24
+ asset: Address;
25
+ pool: Address;
26
+ liquidityProvider: Address;
27
+ };
28
+ export type DSTokenMeta = Omit<SimpleTokenMeta, "isDSToken"> & {
29
+ isDSToken: true;
30
+ };
31
+ export type KYCTokenMeta = KYCDefaultTokenMeta | KYCOnDemandTokenMeta;
32
+ export type TokenMetaData = SimpleTokenMeta | PhantomTokenMeta | KYCTokenMeta | DSTokenMeta;
33
+ export {};
@@ -102,13 +102,6 @@ export type CreditConfiguratorState = CreditSuiteState["creditConfigurator"];
102
102
  * Adapter contract data for a credit suite.
103
103
  **/
104
104
  export type AdapterData = Unarray<CreditSuiteState["adapters"]>;
105
- /**
106
- * On-chain metadata for a single token (symbol, decimals, address).
107
- **/
108
- export type TokenMetaData = Unarray<MarketData["tokens"]>;
109
- /**
110
- * On-chain state of a lending pool.
111
- **/
112
105
  export type PoolState = MarketData["pool"];
113
106
  /**
114
107
  * On-chain state of a quota keeper.
@@ -4,7 +4,7 @@ import { z } from "zod/v4";
4
4
  * Known curator names that manage Gearbox markets.
5
5
  *
6
6
  **/
7
- export type Curator = "Chaos Labs" | "K3" | "cp0x" | "Re7" | "Invariant Group" | "Tulipa" | "M11 Credit" | "kpk" | "Hyperithm" | "UltraYield" | "TelosC" | "Gami Labs";
7
+ export type Curator = "Chaos Labs" | "K3" | "cp0x" | "Re7" | "Invariant Group" | "Tulipa" | "M11 Credit" | "kpk" | "Hyperithm" | "UltraYield" | "TelosC" | "Gami Labs" | "Securitize";
8
8
  /**
9
9
  * Extended viem {@link Chain} with Gearbox-specific metadata.
10
10
  *
@@ -4,5 +4,4 @@ export * from "./bot-permissions.js";
4
4
  export * from "./math.js";
5
5
  export * from "./networks.js";
6
6
  export * from "./periphery.js";
7
- export * from "./phantom-tokens.js";
8
7
  export * from "./versions.js";
@@ -1,6 +1,5 @@
1
1
  import type { Address } from "viem";
2
2
  import type { MarketData, MarketFilter } from "../base/index.js";
3
- import { SDKConstruct } from "../base/index.js";
4
3
  import type { GearboxSDK } from "../GearboxSDK.js";
5
4
  import type { MarketStateHuman } from "../types/index.js";
6
5
  import { AddressMap } from "../utils/index.js";
@@ -9,6 +8,7 @@ import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
9
8
  import { MarketSuite } from "./MarketSuite.js";
10
9
  import type { IPriceOracleContract } from "./oracle/index.js";
11
10
  import type { PoolSuite } from "./pool/index.js";
11
+ import { ZapperRegister } from "./ZapperRegister.js";
12
12
  /**
13
13
  * Central registry of all Gearbox markets on the current chain.
14
14
  *
@@ -16,7 +16,7 @@ import type { PoolSuite } from "./pool/index.js";
16
16
  * managers into a single unit. The `MarketRegister` loads this data from the
17
17
  * on-chain market compressor and exposes convenience lookup methods
18
18
  **/
19
- export declare class MarketRegister extends SDKConstruct {
19
+ export declare class MarketRegister extends ZapperRegister {
20
20
  #private;
21
21
  /**
22
22
  * @param sdk - Top-level SDK instance.
@@ -8,6 +8,7 @@ import { type ILossPolicyContract } from "./loss-policy/index.js";
8
8
  import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
9
9
  import type { IPriceOracleContract } from "./oracle/index.js";
10
10
  import { PoolSuite } from "./pool/index.js";
11
+ import type { SecuritizeKYCFactory } from "./pool/SecuritizeKYCFactory.js";
11
12
  export declare class MarketSuite extends SDKConstruct {
12
13
  readonly acl: Address;
13
14
  readonly treasury: Address;
@@ -21,6 +22,8 @@ export declare class MarketSuite extends SDKConstruct {
21
22
  */
22
23
  readonly state: MarketData;
23
24
  constructor(sdk: GearboxSDK, marketData: MarketData);
25
+ get underlying(): Address;
26
+ getKYCFactory(): Promise<SecuritizeKYCFactory | undefined>;
24
27
  get dirty(): boolean;
25
28
  get watchAddresses(): Set<Address>;
26
29
  stateHuman(raw?: boolean): MarketStateHuman;
@@ -0,0 +1,17 @@
1
+ import type { Address } from "viem";
2
+ import { SDKConstruct } from "../base/index.js";
3
+ import { AddressMap } from "../utils/index.js";
4
+ import type { ZapperData } from "./types.js";
5
+ export declare class ZapperRegister extends SDKConstruct {
6
+ #private;
7
+ /**
8
+ * Load zappers for all pools using periphery compressor, adds hardcoded zappers
9
+ */
10
+ loadZappers(force?: boolean): Promise<void>;
11
+ get zappers(): AddressMap<ZapperData[]>;
12
+ poolZappers(pool: Address): ZapperData[];
13
+ /**
14
+ * Can return multiple zappers if there are multiple zappers for the same tokenIn and tokenOut
15
+ */
16
+ getZapper(pool: Address, tokenIn: Address, tokenOut: Address): Array<ZapperData> | undefined;
17
+ }
@@ -5,3 +5,4 @@ export * from "./MarketSuite.js";
5
5
  export * from "./oracle/index.js";
6
6
  export * from "./pool/index.js";
7
7
  export * from "./pricefeeds/index.js";
8
+ export * from "./types.js";
@@ -6,6 +6,7 @@ import type { PoolSuiteStateHuman } from "../../types/index.js";
6
6
  import type { MarketConfiguratorContract } from "../MarketConfiguratorContract.js";
7
7
  import { GaugeContract } from "./GaugeContract.js";
8
8
  import { LinearInterestRateModelContract } from "./LinearInterestRateModelContract.js";
9
+ import type { SecuritizeKYCFactory } from "./SecuritizeKYCFactory.js";
9
10
  import { TumblerContract } from "./TumblerContract.js";
10
11
  import type { IInterestRateModelContract, IRateKeeperContract, PoolContract, PoolQuotaKeeperContract } from "./types.js";
11
12
  export declare class PoolSuite extends SDKConstruct {
@@ -20,6 +21,7 @@ export declare class PoolSuite extends SDKConstruct {
20
21
  get linearModel(): LinearInterestRateModelContract;
21
22
  get marketConfigurator(): MarketConfiguratorContract;
22
23
  get underlying(): Address;
24
+ getKYCFactory(): Promise<SecuritizeKYCFactory | undefined>;
23
25
  get dirty(): boolean;
24
26
  get watchAddresses(): Set<Address>;
25
27
  stateHuman(raw?: boolean): PoolSuiteStateHuman;
@@ -1,8 +1,10 @@
1
1
  import type { ContractEventName, DecodeFunctionDataReturnType, Log } from "viem";
2
- import type { ConstructOptions, CreditManagerDebtParams, PoolState } from "../../base/index.js";
2
+ import type { CreditManagerDebtParams, PoolState } from "../../base/index.js";
3
3
  import { BaseContract } from "../../base/index.js";
4
+ import type { GearboxSDK } from "../../GearboxSDK.js";
4
5
  import type { PoolStateHuman } from "../../types/index.js";
5
6
  import { AddressMap } from "../../utils/index.js";
7
+ import { SecuritizeKYCFactory } from "./SecuritizeKYCFactory.js";
6
8
  declare const abi: readonly [{
7
9
  readonly type: "function";
8
10
  readonly inputs: readonly [];
@@ -1130,8 +1132,10 @@ type abi = typeof abi;
1130
1132
  export interface PoolV310Contract extends Omit<PoolState, "baseParams" | "creditManagerDebtParams" | "name">, BaseContract<abi> {
1131
1133
  }
1132
1134
  export declare class PoolV310Contract extends BaseContract<abi> {
1135
+ #private;
1133
1136
  readonly creditManagerDebtParams: AddressMap<CreditManagerDebtParams>;
1134
- constructor(options: ConstructOptions, data: PoolState);
1137
+ constructor(sdk: GearboxSDK, data: PoolState);
1138
+ getKYCFactory(): Promise<SecuritizeKYCFactory | undefined>;
1135
1139
  stateHuman(raw?: boolean): PoolStateHuman;
1136
1140
  processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
1137
1141
  protected stringifyFunctionParams(params: DecodeFunctionDataReturnType<abi>): string[];