@gearbox-protocol/sdk 13.2.1 → 13.3.0-next.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 (99) 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/dev/index.js +2 -2
  6. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +462 -104
  7. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +16 -5
  8. package/dist/cjs/sdk/base/ChainContractsRegister.js +1 -1
  9. package/dist/cjs/sdk/base/TokensMeta.js +255 -32
  10. package/dist/cjs/sdk/base/index.js +2 -0
  11. package/dist/cjs/sdk/{constants/phantom-tokens.js → base/token-types.js} +9 -3
  12. package/dist/cjs/sdk/chain/chains.js +2 -1
  13. package/dist/cjs/sdk/constants/index.js +0 -2
  14. package/dist/cjs/sdk/market/MarketRegister.js +2 -2
  15. package/dist/cjs/sdk/market/MarketSuite.js +6 -0
  16. package/dist/cjs/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +110 -6
  17. package/dist/cjs/sdk/market/index.js +3 -1
  18. package/dist/cjs/sdk/market/pool/PoolSuite.js +3 -0
  19. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +17 -2
  20. package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +97 -0
  21. package/dist/cjs/sdk/market/pool/index.js +4 -0
  22. package/dist/cjs/sdk/pools/PoolService.js +391 -0
  23. package/dist/cjs/sdk/pools/index.js +2 -4
  24. package/dist/cjs/sdk/utils/AddressMap.js +1 -1
  25. package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
  26. package/dist/esm/abi/310/iSecuritizeDegenNFT.js +239 -0
  27. package/dist/esm/abi/310/iSecuritizeKYCFactory.js +254 -0
  28. package/dist/esm/abi/iStateSerializer.js +12 -0
  29. package/dist/esm/dev/AccountOpener.js +47 -6
  30. package/dist/esm/dev/index.js +1 -1
  31. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +462 -104
  32. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +16 -5
  33. package/dist/esm/sdk/base/ChainContractsRegister.js +1 -1
  34. package/dist/esm/sdk/base/TokensMeta.js +261 -32
  35. package/dist/esm/sdk/base/index.js +1 -0
  36. package/dist/esm/sdk/{constants/phantom-tokens.js → base/token-types.js} +4 -0
  37. package/dist/esm/sdk/chain/chains.js +2 -1
  38. package/dist/esm/sdk/constants/index.js +0 -1
  39. package/dist/esm/sdk/market/MarketRegister.js +2 -2
  40. package/dist/esm/sdk/market/MarketSuite.js +6 -0
  41. package/dist/esm/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +109 -2
  42. package/dist/esm/sdk/market/index.js +1 -0
  43. package/dist/esm/sdk/market/pool/PoolSuite.js +3 -0
  44. package/dist/esm/sdk/market/pool/PoolV310Contract.js +17 -2
  45. package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +73 -0
  46. package/dist/esm/sdk/market/pool/index.js +2 -0
  47. package/dist/esm/sdk/pools/PoolService.js +371 -0
  48. package/dist/esm/sdk/pools/index.js +1 -2
  49. package/dist/esm/sdk/utils/AddressMap.js +1 -1
  50. package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
  51. package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +324 -0
  52. package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +322 -0
  53. package/dist/types/abi/iStateSerializer.d.ts +11 -0
  54. package/dist/types/dev/index.d.ts +1 -1
  55. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +123 -27
  56. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  57. package/dist/types/sdk/accounts/types.d.ts +108 -8
  58. package/dist/types/sdk/base/TokensMeta.d.ts +34 -18
  59. package/dist/types/sdk/base/index.d.ts +1 -0
  60. package/dist/types/sdk/base/token-types.d.ts +33 -0
  61. package/dist/types/sdk/base/types.d.ts +0 -1
  62. package/dist/types/sdk/chain/chains.d.ts +1 -1
  63. package/dist/types/sdk/constants/index.d.ts +0 -1
  64. package/dist/types/sdk/market/MarketRegister.d.ts +2 -2
  65. package/dist/types/sdk/market/MarketSuite.d.ts +3 -0
  66. package/dist/types/sdk/market/ZapperRegister.d.ts +17 -0
  67. package/dist/types/sdk/market/index.d.ts +1 -0
  68. package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -0
  69. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +6 -2
  70. package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +345 -0
  71. package/dist/types/sdk/market/pool/index.d.ts +2 -0
  72. package/dist/types/sdk/market/types.d.ts +10 -0
  73. package/dist/types/sdk/pools/PoolService.d.ts +14 -0
  74. package/dist/types/sdk/pools/index.d.ts +1 -2
  75. package/dist/types/sdk/pools/types.d.ts +84 -63
  76. package/dist/types/sdk/utils/AddressMap.d.ts +1 -1
  77. package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
  78. package/package.json +1 -1
  79. package/dist/cjs/plugins/zappers/ZappersPlugin.js +0 -144
  80. package/dist/cjs/plugins/zappers/index.js +0 -26
  81. package/dist/cjs/plugins/zappers/package.json +0 -1
  82. package/dist/cjs/sdk/pools/AbstractPoolService.js +0 -137
  83. package/dist/cjs/sdk/pools/createPoolService.js +0 -35
  84. package/dist/esm/plugins/zappers/ZappersPlugin.js +0 -126
  85. package/dist/esm/plugins/zappers/index.js +0 -3
  86. package/dist/esm/plugins/zappers/package.json +0 -1
  87. package/dist/esm/sdk/pools/AbstractPoolService.js +0 -113
  88. package/dist/esm/sdk/pools/PoolServiceV310.js +0 -6
  89. package/dist/esm/sdk/pools/createPoolService.js +0 -11
  90. package/dist/types/plugins/zappers/ZappersPlugin.d.ts +0 -18
  91. package/dist/types/plugins/zappers/extraZappers.d.ts +0 -6
  92. package/dist/types/plugins/zappers/index.d.ts +0 -3
  93. package/dist/types/plugins/zappers/types.d.ts +0 -12
  94. package/dist/types/sdk/constants/phantom-tokens.d.ts +0 -2
  95. package/dist/types/sdk/pools/AbstractPoolService.d.ts +0 -9
  96. package/dist/types/sdk/pools/PoolServiceV310.d.ts +0 -4
  97. package/dist/types/sdk/pools/createPoolService.d.ts +0 -3
  98. /package/dist/cjs/{plugins/zappers → sdk/market}/types.js +0 -0
  99. /package/dist/esm/{plugins/zappers → sdk/market}/types.js +0 -0
@@ -2,10 +2,10 @@ 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 { OnDemandPriceUpdates, UpdatePriceFeedsResult } from "../market/index.js";
5
+ import type { CreditSuite, MarketSuite, OnDemandPriceUpdates, UpdatePriceFeedsResult } from "../market/index.js";
6
6
  import { type Asset, type RouterCASlice } from "../router/index.js";
7
- import type { MultiCall } from "../types/index.js";
8
- import type { AccountToCheck, AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, PriceUpdatesOptions, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
7
+ import type { IPriceUpdateTx, MultiCall, RawTx } from "../types/index.js";
8
+ import type { AccountToCheck, AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CloseOptions, CreditAccountDataWithInvestor, CreditAccountOperationResult, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, PriceUpdatesOptions, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
9
9
  export interface CreditAccountServiceOptions {
10
10
  batchSize?: number;
11
11
  }
@@ -21,6 +21,14 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
21
21
  * @returns
22
22
  */
23
23
  getCreditAccountData(account: Address, blockNumber?: bigint): Promise<CreditAccountData | undefined>;
24
+ /**
25
+ * Returns credit account data for a single account with the investor address resolved.
26
+ * Loads CA via getCreditAccountData; for KYC underlyings fetches the investor from the KYC factory's getInvestor(creditAccount), otherwise uses the account owner.
27
+ * @param account - Credit account address
28
+ * @param blockNumber - Optional block number for the read
29
+ * @returns CreditAccountDataWithInvestor (CA data + investor address), or undefined if the account is not found
30
+ */
31
+ getCreditAccountDataWithInvestor(account: Address, blockNumber?: bigint): Promise<CreditAccountDataWithInvestor | undefined>;
24
32
  /**
25
33
  * Methods to get all credit accounts with some optional filtering
26
34
  * Performs all necessary price feed updates under the hood
@@ -29,7 +37,31 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
29
37
  * @param blockNumber
30
38
  * @returns returned credit accounts are sorted by health factor in ascending order
31
39
  */
32
- getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountData>>;
40
+ getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint, priceUpdate?: UpdatePriceFeedsResult): Promise<Array<CreditAccountData>>;
41
+ /**
42
+ * Returns all credit accounts matching the filter, with investor set on each item.
43
+ * 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.
44
+ * @param options - Filter options (owner, creditManager, health factor, etc.)
45
+ * @param blockNumber - Optional block number for the read
46
+ * @returns Array of credit accounts (with investor field), sorted by health factor ascending
47
+ */
48
+ getCreditAccountsWithInvestor(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountDataWithInvestor>>;
49
+ protected getKYCCreditAccountsOfOwner(owner: Address, priceUpdateTxs: IPriceUpdateTx<{
50
+ priceFeed: `0x${string}`;
51
+ timestamp: number;
52
+ }>[], blockNumber?: bigint): Promise<Array<CreditAccountDataWithInvestor>>;
53
+ /**
54
+ * Loads credit account data for the given addresses using simulateWithPriceUpdates.
55
+ * Applies the provided price update txs before reading, so returned data is consistent with up-to-date prices.
56
+ * @param accounts - Credit account addresses to load
57
+ * @param priceUpdateTxs - Price feed update txs to simulate before the read (e.g. from generatePriceFeedsUpdateTxs)
58
+ * @param blockNumber - Optional block number for the read
59
+ * @returns Array of CreditAccountData in the same order as accounts (throws if any getCreditAccountData call reverts)
60
+ */
61
+ loadSpecifiedAccounts(accounts: Address[], priceUpdateTxs: IPriceUpdateTx<{
62
+ priceFeed: `0x${string}`;
63
+ timestamp: number;
64
+ }>[], blockNumber?: bigint): Promise<Array<CreditAccountData>>;
33
65
  /**
34
66
  * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
35
67
  Assosiates rewards by adapter + stakedPhantomToken
@@ -104,7 +136,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
104
136
  positive value for debt increase.
105
137
  * @returns All necessary data to execute the transaction (call, credit facade)
106
138
  */
107
- changeDebt({ creditAccount, amount, addCollateral, }: ChangeDeptProps): Promise<CreditAccountOperationResult>;
139
+ changeDebt({ creditAccount, amount, collateral, }: ChangeDeptProps): Promise<CreditAccountOperationResult>;
108
140
  /**
109
141
  * Executes swap specified by given calls, update quotas of affected tokens
110
142
  - Swap is executed in the following order: price update -> execute swap path -> update quotas
@@ -141,31 +173,25 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
141
173
  * @returns
142
174
  */
143
175
  claimDelayed({ creditAccount, minQuota, averageQuota, claimableNow, }: ClaimDelayedProps): Promise<CreditAccountOperationResult>;
176
+ /**
177
+ * Returns address to which approval should be given on collateral token
178
+ * It's credit manager for classical markets and special wallet for KYC markets
179
+ * @param options - {@link GetApprovalAddressProps}
180
+ * @returns
181
+ **/
182
+ getApprovalAddress(options: GetApprovalAddressProps): Promise<Address>;
144
183
  /**
145
184
  * Executes swap specified by given calls, update quotas of affected tokens
146
- - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
147
- -> update quotas -> (optionally: execute swap path for trading/strategy) ->
148
- -> (optionally: withdraw debt for lending)
149
- - Basic open credit account: price update -> increase debt -> add collateral -> update quotas
150
- - Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
151
- - Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
152
- - In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
153
- * @param {bigint} ethAmount - native token amount to attach to tx
154
- * @param {Address} creditManager - address of credit manager to open credit account on
155
- * @param {Array<Asset>} collateral - array of collateral which can be just directly added or swapped using the path {@link Asset}
156
- * @param {Record<Address, PermitResult>} permits - permits of collateral tokens (in any permittable token is present) {@link PermitResult}
157
- * @param {bigint} debt - debt to open credit account with
158
- * @param {boolean} withdrawDebt - flag to withdraw debt to wallet after opening credit account;
159
- used for borrowing functionality
160
- * @param {bigint} referralCode - referral code to open credit account with
161
- * @param {Address} to - wallet address to transfer credit account to\
162
- * @param {Array<MultiCall>} calls - array of MultiCall from router methods findOpenStrategyPath {@link MultiCall}.
163
- Used for trading and strategy functionality
164
- * @param {Array<Asset>} averageQuota - average quota for tokens after open {@link Asset}
165
- * @param {Array<Asset>} minQuota - minimum quota for tokens after open {@link Asset}
185
+ * - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
186
+ * -> update quotas -> (optionally: execute swap path for trading/strategy) ->
187
+ * -> (optionally: withdraw debt for lending)
188
+ *- Basic open credit account: price update -> increase debt -> add collateral -> update quotas
189
+ *- Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
190
+ *- Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
191
+ *- In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
166
192
  * @returns All necessary data to execute the transaction (call, credit facade)
167
- */
168
- openCA({ ethAmount, creditManager, collateral, permits, debt, withdrawDebt, referralCode, to, calls: openPathCalls, minQuota, averageQuota, }: OpenCAProps): Promise<CreditAccountOperationResult>;
193
+ **/
194
+ openCA(props: OpenCAProps): Promise<CreditAccountOperationResult>;
169
195
  /**
170
196
  * Returns borrow rate with 4 digits precision (10000 = 100%)
171
197
  * @param ca
@@ -177,6 +203,42 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
177
203
  * @param ca
178
204
  */
179
205
  getOptimalHFForPartialLiquidation(ca: CreditAccountData): bigint;
206
+ /**
207
+ * Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
208
+ * Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
209
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
210
+ * @param amount - Number of vault shares (adapter tokens) to redeem
211
+ * @param creditManager - Credit manager address
212
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
213
+ */
214
+ getKYCUnwrapCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
215
+ /**
216
+ * Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
217
+ * Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
218
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
219
+ * @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
220
+ * @param creditManager - Credit manager address
221
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
222
+ */
223
+ getKYCWrapCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
224
+ /**
225
+ * Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
226
+ * Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
227
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
228
+ * @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
229
+ * @param creditManager - Credit manager address
230
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
231
+ */
232
+ getRedeemDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
233
+ /**
234
+ * Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
235
+ * Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
236
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
237
+ * @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
238
+ * @param creditManager - Credit manager address
239
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
240
+ */
241
+ getDepositDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
180
242
  /**
181
243
  * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
182
244
  *
@@ -212,4 +274,38 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
212
274
  private get marketConfigurators();
213
275
  private get rewardCompressor();
214
276
  private get peripheryCompressor();
277
+ /**
278
+ * Wrapper that selects between credit facade and KYC factory
279
+ * @param suite
280
+ * @param to
281
+ * @param calls
282
+ * @param referralCode
283
+ * @returns
284
+ */
285
+ protected openCreditAccountTx(suite: CreditSuite, to: Address, calls: MultiCall[], referralCode?: bigint): Promise<RawTx>;
286
+ /**
287
+ * Wrapper that selects between credit facade and KYC factory
288
+ * @param suite
289
+ * @param creditAccount
290
+ * @param calls
291
+ * @returns
292
+ */
293
+ protected multicallTx(suite: CreditSuite, creditAccount: Address, calls: MultiCall[]): Promise<RawTx>;
294
+ /**
295
+ * Wrapper that selects between credit facade and KYC factory
296
+ * @param suite
297
+ * @param creditAccount
298
+ * @param calls
299
+ * @param operation
300
+ * @returns
301
+ */
302
+ protected closeCreditAccountTx(suite: CreditSuite, creditAccount: Address, calls: MultiCall[], operation: CloseOptions): Promise<RawTx>;
303
+ /**
304
+ * Returns all KYC credit account addresses for an investor across the given market suites.
305
+ * Resolves KYC factory per suite, then multicalls each factory's getCreditAccounts(investor).
306
+ * @param investor - Owner address to query
307
+ * @param suites - Market suites (KYC factories are resolved for each; undefined entries are skipped)
308
+ * @returns Flat array of credit account addresses from all KYC markets
309
+ */
310
+ protected getKYCCaOfInvestor(investor: Address, suites: Array<MarketSuite | undefined>): Promise<`0x${string}`[]>;
215
311
  }
@@ -12,7 +12,7 @@ export declare class CreditAccountServiceV310 extends AbstractCreditAccountServi
12
12
  /**
13
13
  * Implements {@link ICreditAccountsService.repayCreditAccount}
14
14
  */
15
- repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, tokensToClaim, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
15
+ repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, tokensToClaim, calls: wrapCalls, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
16
16
  /**
17
17
  * Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
18
18
  */
@@ -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, OnDemandPriceUpdates, UpdatePriceFeedsResult } from "../market/index.js";
7
7
  import type { Asset, CreditAccountTokensSlice, 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
  export type GetCreditAccountsArgs = ContractFunctionArgs<typeof creditAccountCompressorAbi, "pure" | "view", "getCreditAccounts">;
10
10
  export interface CreditAccountFilter {
11
11
  owner: Address;
@@ -83,6 +83,10 @@ export interface CloseCreditAccountProps {
83
83
  closePath?: RouterCloseResult;
84
84
  }
85
85
  export interface RepayCreditAccountProps extends RepayAndLiquidateCreditAccountProps {
86
+ /**
87
+ * Swap calls for repay
88
+ */
89
+ calls?: Array<MultiCall>;
86
90
  /**
87
91
  * close or zeroDebt
88
92
  */
@@ -263,8 +267,9 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
263
267
  /**
264
268
  * Flag to withdraw debt to wallet after opening credit account;
265
269
  * used for borrowing functionality
270
+ * If true, will withdraw underlying token, otherwise will withdraw specified token
266
271
  */
267
- withdrawDebt?: boolean;
272
+ withdrawToken?: boolean | Address;
268
273
  /**
269
274
  * Permits of collateral tokens (in any permittable token is present) {@link PermitResult}
270
275
  */
@@ -274,10 +279,19 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
274
279
  * Used for trading and strategy functionality
275
280
  */
276
281
  calls: Array<MultiCall>;
282
+ /**
283
+ * Slot for optional call to execute after main tx.
284
+ * For example: add bots
285
+ */
286
+ callsAfter?: Array<MultiCall>;
277
287
  /**
278
288
  * Address of credit manager to open credit account on
279
289
  */
280
290
  creditManager: Address;
291
+ /**
292
+ * Optional address of credit account to reopen
293
+ */
294
+ reopenCreditAccount?: Address;
281
295
  /**
282
296
  * Wallet address to transfer credit account to
283
297
  */
@@ -300,9 +314,13 @@ export interface ChangeDeptProps {
300
314
  */
301
315
  amount: bigint;
302
316
  /**
303
- * If true, will add collateral to the credit account
317
+ * Assets to add as collateral
304
318
  */
305
- addCollateral: boolean;
319
+ collateral?: [Asset];
320
+ /**
321
+ * Assets to wrap
322
+ */
323
+ wrapAsset?: [Asset];
306
324
  }
307
325
  export interface FullyLiquidateProps {
308
326
  /**
@@ -418,6 +436,19 @@ export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotas
418
436
  */
419
437
  creditAccount: RouterCASlice;
420
438
  }
439
+ /**
440
+ * Options to get approval address for collateral token
441
+ */
442
+ export type GetApprovalAddressProps = {
443
+ creditManager: Address;
444
+ borrower: Address;
445
+ } | {
446
+ creditManager: Address;
447
+ creditAccount: Address;
448
+ };
449
+ export type CreditAccountDataWithInvestor = CreditAccountData & {
450
+ investor: Address;
451
+ };
421
452
  export interface ICreditAccountsService extends Construct {
422
453
  sdk: GearboxSDK;
423
454
  /**
@@ -428,15 +459,41 @@ export interface ICreditAccountsService extends Construct {
428
459
  * @returns
429
460
  */
430
461
  getCreditAccountData(account: Address, blockNumber?: bigint): Promise<CreditAccountData | undefined>;
462
+ /**
463
+ * Returns credit account data for a single account with the investor address resolved (from KYC factory when applicable).
464
+ * @param account - Credit account address
465
+ * @param blockNumber - Optional block number for the read
466
+ * @returns CreditAccountDataWithInvestor, or undefined if the account is not found
467
+ */
468
+ getCreditAccountDataWithInvestor(account: Address, blockNumber?: bigint): Promise<CreditAccountDataWithInvestor | undefined>;
431
469
  /**
432
470
  * Methods to get all credit accounts with some optional filtering
433
471
  * Performs all necessary price feed updates under the hood
434
472
  *
435
473
  * @param options
436
474
  * @param blockNumber
437
- * @returns returned credit accounts are sorted by health factor in ascending order
475
+ * @param priceUpdate - Optional pre-computed price feed update (e.g. from generatePriceFeedsUpdateTxs)
476
+ * @returns Credit accounts sorted by health factor ascending
477
+ */
478
+ getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint, priceUpdate?: UpdatePriceFeedsResult): Promise<Array<CreditAccountData>>;
479
+ /**
480
+ * Returns all credit accounts matching the filter with investor set on each; when options.owner is set, includes KYC CAs for that owner.
481
+ * @param options - Filter options (owner, creditManager, health factor, etc.)
482
+ * @param blockNumber - Optional block number for the read
483
+ * @returns Credit accounts (with investor) sorted by health factor ascending
484
+ */
485
+ getCreditAccountsWithInvestor(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountDataWithInvestor>>;
486
+ /**
487
+ * Loads credit account data for the given addresses using simulateWithPriceUpdates (with price updates applied before the read).
488
+ * @param accounts - Credit account addresses to load
489
+ * @param priceUpdateTxs - Price feed update txs to simulate before the read (e.g. from generatePriceFeedsUpdateTxs)
490
+ * @param blockNumber - Optional block number for the read
491
+ * @returns Array of CreditAccountData in the same order as accounts
438
492
  */
439
- getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountData>>;
493
+ loadSpecifiedAccounts(accounts: Address[], priceUpdateTxs: IPriceUpdateTx<{
494
+ priceFeed: `0x${string}`;
495
+ timestamp: number;
496
+ }>[], blockNumber?: bigint): Promise<Array<CreditAccountData>>;
440
497
  /**
441
498
  * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
442
499
  * Assosiates rewards by adapter + stakedPhantomToken
@@ -465,9 +522,9 @@ export interface ICreditAccountsService extends Construct {
465
522
  /**
466
523
  * Generates transaction to liquidate credit account
467
524
  * @param props - {@link FullyLiquidateProps}
468
- * @returns
525
+ * @returns Transaction data and optional loss policy data
469
526
  */
470
- fullyLiquidate(props: FullyLiquidateProps): Promise<CloseCreditAccountResult>;
527
+ fullyLiquidate(props: FullyLiquidateProps): Promise<FullyLiquidateResult>;
471
528
  /**
472
529
  * Closes credit account or closes credit account and keeps it open with zero debt.
473
530
  * - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
@@ -530,6 +587,13 @@ export interface ICreditAccountsService extends Construct {
530
587
  * @returns
531
588
  */
532
589
  claimDelayed(props: ClaimDelayedProps): Promise<CreditAccountOperationResult>;
590
+ /**
591
+ * Returns address to which approval should be given on collateral token
592
+ * It's credit manager for classical markets and special wallet for KYC markets
593
+ * @param props - {@link GetApprovalAddressProps}
594
+ * @returns
595
+ */
596
+ getApprovalAddress(props: GetApprovalAddressProps): Promise<Address>;
533
597
  /**
534
598
  * Executes swap specified by given calls, update quotas of affected tokens
535
599
  * - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
@@ -574,6 +638,42 @@ export interface ICreditAccountsService extends Construct {
574
638
  * @returns
575
639
  */
576
640
  getPriceUpdatesForFacade(options: PriceUpdatesOptions): Promise<Array<MultiCall>>;
641
+ /**
642
+ * Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
643
+ * Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
644
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
645
+ * @param amount - Number of vault shares (adapter tokens) to redeem
646
+ * @param creditManager - Credit manager address
647
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
648
+ */
649
+ getKYCUnwrapCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
650
+ /**
651
+ * Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
652
+ * Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
653
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
654
+ * @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
655
+ * @param creditManager - Credit manager address
656
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
657
+ */
658
+ getKYCWrapCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
659
+ /**
660
+ * Returns multicall entries to call redeemDiff on the KYC ERC-4626 adapter for the given credit manager.
661
+ * Redeems the leftover vault shares (e.g. after repaying debt) so the account does not hold excess KYC vault tokens.
662
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
663
+ * @param amount - Leftover vault share amount to redeem (in adapter/vault decimals)
664
+ * @param creditManager - Credit manager address
665
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
666
+ */
667
+ getRedeemDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
668
+ /**
669
+ * Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
670
+ * Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
671
+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
672
+ * @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
673
+ * @param creditManager - Credit manager address
674
+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
675
+ */
676
+ getDepositDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
577
677
  /**
578
678
  * Withdraws a single collateral from credit account to wallet to and updates quotas;
579
679
  * technically can withdraw several tokens at once
@@ -1,40 +1,56 @@
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
  export interface FormatBNOptions {
7
7
  precision?: number;
8
8
  symbol?: boolean;
9
9
  }
10
- export interface TokenMetaDataExtended extends TokenMetaData {
11
- /**
12
- * Undefined if token is not a phantom token
13
- */
14
- phantomTokenType?: PhantomTokenContractType;
15
- }
16
- export declare class TokensMeta extends AddressMap<TokenMetaDataExtended> {
10
+ export declare class TokensMeta extends AddressMap<TokenMetaData> {
17
11
  #private;
18
- constructor(client: PublicClient<Transport, Chain>);
12
+ constructor(client: PublicClient<Transport, Chain>, logger?: ILogger);
19
13
  reset(): void;
14
+ upsert(address: string, value: TokenMetaData | undefined): void;
20
15
  symbol(token: Address): string;
21
16
  decimals(token: Address): number;
22
17
  /**
23
- * Returns the phantom token type for a given token, or undefined for normal tokens
24
- * Throws if the phantom token data is not loaded
18
+ * Returns true if the token is a phantom token, throws if the token data is not loaded
19
+ * @param t
20
+ * @returns
21
+ */
22
+ isPhantomToken(t: TokenMetaData): t is PhantomTokenMeta;
23
+ /**
24
+ * Returns true if the token is a KYC underlying token, throws if the token data is not loaded
25
+ * @param t
26
+ * @returns
25
27
  */
26
- phantomTokenType(token: Address): PhantomTokenContractType | undefined;
28
+ isKYCUnderlying(t: TokenMetaData): t is KYCTokenMeta;
29
+ /**
30
+ * Returns true if the token is a DSToken, throws if the token data is not loaded
31
+ * @param t
32
+ * @returns
33
+ */
34
+ isDSToken(t: TokenMetaData): t is DSTokenMeta;
27
35
  /**
28
36
  * Returns a map of all phantom tokens
29
- * Throws if the phantom token data is not loaded
37
+ * Throws if token data is not loaded
38
+ */
39
+ get phantomTokens(): AddressMap<PhantomTokenMeta>;
40
+ /**
41
+ * Returns a map of all KYC underlying tokens
42
+ * Throws if token data is not loaded
30
43
  */
31
- get phantomTokens(): AddressMap<TokenMetaDataExtended>;
44
+ get kycUnderlyings(): AddressMap<KYCTokenMeta>;
45
+ get dsTokens(): AddressMap<DSTokenMeta>;
32
46
  formatBN(asset: Asset, options?: FormatBNOptions): string;
33
47
  formatBN(token: Address, amount: number | bigint | string | undefined, options?: FormatBNOptions): string;
34
48
  findBySymbol(symbol: string): TokenMetaData | undefined;
35
49
  mustFindBySymbol(symbol: string): TokenMetaData;
36
50
  /**
37
- * Loads phantom token data for all known tokens from chain
51
+ * Loads token information about phantom tokens, KYC underlying tokens and DSTokens
52
+ *
53
+ * @param tokens - tokens to load data for, defaults to all tokens
38
54
  */
39
- loadPhantomTokens(): Promise<void>;
55
+ loadTokenData(...tokens: Address[]): Promise<void>;
40
56
  }
@@ -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 {};
@@ -35,7 +35,6 @@ export type CreditManagerState = CreditSuiteState["creditManager"];
35
35
  export type CreditFacadeState = CreditSuiteState["creditFacade"];
36
36
  export type CreditConfiguratorState = CreditSuiteState["creditConfigurator"];
37
37
  export type AdapterData = Unarray<CreditSuiteState["adapters"]>;
38
- export type TokenMetaData = Unarray<MarketData["tokens"]>;
39
38
  export type PoolState = MarketData["pool"];
40
39
  export type QuotaKeeperState = MarketData["quotaKeeper"];
41
40
  export type QuotaState = Unarray<QuotaKeeperState["quotas"]>;
@@ -1,6 +1,6 @@
1
1
  import type { Address, Chain } from "viem";
2
2
  import { z } from "zod/v4";
3
- export type Curator = "Chaos Labs" | "K3" | "cp0x" | "Re7" | "Invariant Group" | "Tulipa" | "M11 Credit" | "kpk" | "Hyperithm" | "UltraYield" | "TelosC" | "Gami Labs";
3
+ export type Curator = "Chaos Labs" | "K3" | "cp0x" | "Re7" | "Invariant Group" | "Tulipa" | "M11 Credit" | "kpk" | "Hyperithm" | "UltraYield" | "TelosC" | "Gami Labs" | "Securitize";
4
4
  export interface GearboxChain extends Chain {
5
5
  network: NetworkType;
6
6
  defaultMarketConfigurators: Record<Address, Curator>;
@@ -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,7 +8,8 @@ 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";
12
- export declare class MarketRegister extends SDKConstruct {
11
+ import { ZapperRegister } from "./ZapperRegister.js";
12
+ export declare class MarketRegister extends ZapperRegister {
13
13
  #private;
14
14
  constructor(sdk: GearboxSDK, ignoreMarkets?: Address[]);
15
15
  hydrate(state: MarketData[]): void;
@@ -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;