@gearbox-protocol/sdk 13.2.0-next.1 → 13.2.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 (105) hide show
  1. package/dist/cjs/dev/AccountOpener.js +5 -45
  2. package/dist/cjs/dev/index.js +13 -0
  3. package/dist/cjs/dev/isTransientError.js +5 -1
  4. package/dist/cjs/dev/logSplitterTransport.js +154 -0
  5. package/dist/cjs/plugins/zappers/ZappersPlugin.js +144 -0
  6. package/dist/cjs/{sdk/market/ZapperRegister.js → plugins/zappers/extraZappers.js} +6 -110
  7. package/dist/cjs/plugins/zappers/index.js +26 -0
  8. package/dist/cjs/plugins/zappers/package.json +1 -0
  9. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +104 -462
  10. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +5 -16
  11. package/dist/cjs/sdk/base/ChainContractsRegister.js +1 -1
  12. package/dist/cjs/sdk/base/TokensMeta.js +32 -255
  13. package/dist/cjs/sdk/base/index.js +0 -2
  14. package/dist/cjs/sdk/chain/chains.js +1 -2
  15. package/dist/cjs/sdk/constants/index.js +2 -0
  16. package/dist/cjs/sdk/{base/token-types.js → constants/phantom-tokens.js} +3 -9
  17. package/dist/cjs/sdk/market/MarketRegister.js +2 -2
  18. package/dist/cjs/sdk/market/MarketSuite.js +0 -6
  19. package/dist/cjs/sdk/market/index.js +1 -3
  20. package/dist/cjs/sdk/market/pool/PoolSuite.js +0 -3
  21. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +2 -17
  22. package/dist/cjs/sdk/market/pool/index.js +0 -4
  23. package/dist/cjs/sdk/pools/AbstractPoolService.js +137 -0
  24. package/dist/cjs/{abi/iStateSerializer.js → sdk/pools/PoolServiceV310.js} +8 -14
  25. package/dist/cjs/sdk/pools/createPoolService.js +35 -0
  26. package/dist/cjs/sdk/pools/index.js +4 -2
  27. package/dist/cjs/sdk/utils/AddressMap.js +1 -1
  28. package/dist/cjs/sdk/utils/viem/sendRawTx.js +0 -16
  29. package/dist/esm/dev/AccountOpener.js +6 -47
  30. package/dist/esm/dev/index.js +10 -0
  31. package/dist/esm/dev/isTransientError.js +5 -1
  32. package/dist/esm/dev/logSplitterTransport.js +131 -0
  33. package/dist/esm/plugins/zappers/ZappersPlugin.js +126 -0
  34. package/dist/esm/{sdk/market/ZapperRegister.js → plugins/zappers/extraZappers.js} +2 -109
  35. package/dist/esm/plugins/zappers/index.js +3 -0
  36. package/dist/esm/plugins/zappers/package.json +1 -0
  37. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +104 -462
  38. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +5 -16
  39. package/dist/esm/sdk/base/ChainContractsRegister.js +1 -1
  40. package/dist/esm/sdk/base/TokensMeta.js +32 -261
  41. package/dist/esm/sdk/base/index.js +0 -1
  42. package/dist/esm/sdk/chain/chains.js +1 -2
  43. package/dist/esm/sdk/constants/index.js +1 -0
  44. package/dist/esm/sdk/{base/token-types.js → constants/phantom-tokens.js} +0 -4
  45. package/dist/esm/sdk/market/MarketRegister.js +2 -2
  46. package/dist/esm/sdk/market/MarketSuite.js +0 -6
  47. package/dist/esm/sdk/market/index.js +0 -1
  48. package/dist/esm/sdk/market/pool/PoolSuite.js +0 -3
  49. package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -17
  50. package/dist/esm/sdk/market/pool/index.js +0 -2
  51. package/dist/esm/sdk/pools/AbstractPoolService.js +113 -0
  52. package/dist/esm/sdk/pools/PoolServiceV310.js +6 -0
  53. package/dist/esm/sdk/pools/createPoolService.js +11 -0
  54. package/dist/esm/sdk/pools/index.js +2 -1
  55. package/dist/esm/sdk/utils/AddressMap.js +1 -1
  56. package/dist/esm/sdk/utils/viem/sendRawTx.js +1 -19
  57. package/dist/types/dev/index.d.ts +1 -0
  58. package/dist/types/dev/logSplitterTransport.d.ts +118 -0
  59. package/dist/types/plugins/zappers/ZappersPlugin.d.ts +18 -0
  60. package/dist/types/plugins/zappers/extraZappers.d.ts +6 -0
  61. package/dist/types/plugins/zappers/index.d.ts +3 -0
  62. package/dist/types/plugins/zappers/types.d.ts +12 -0
  63. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +27 -123
  64. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  65. package/dist/types/sdk/accounts/types.d.ts +8 -108
  66. package/dist/types/sdk/base/TokensMeta.d.ts +18 -34
  67. package/dist/types/sdk/base/index.d.ts +0 -1
  68. package/dist/types/sdk/base/types.d.ts +1 -0
  69. package/dist/types/sdk/chain/chains.d.ts +1 -1
  70. package/dist/types/sdk/constants/index.d.ts +1 -0
  71. package/dist/types/sdk/constants/phantom-tokens.d.ts +2 -0
  72. package/dist/types/sdk/market/MarketRegister.d.ts +2 -2
  73. package/dist/types/sdk/market/MarketSuite.d.ts +0 -3
  74. package/dist/types/sdk/market/credit/CreditFacadeV310BaseContract.d.ts +1 -1
  75. package/dist/types/sdk/market/index.d.ts +0 -1
  76. package/dist/types/sdk/market/pool/PoolSuite.d.ts +0 -2
  77. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +2 -6
  78. package/dist/types/sdk/market/pool/index.d.ts +0 -2
  79. package/dist/types/sdk/pools/AbstractPoolService.d.ts +9 -0
  80. package/dist/types/sdk/pools/PoolServiceV310.d.ts +4 -0
  81. package/dist/types/sdk/pools/createPoolService.d.ts +3 -0
  82. package/dist/types/sdk/pools/index.d.ts +2 -1
  83. package/dist/types/sdk/pools/types.d.ts +63 -84
  84. package/dist/types/sdk/utils/AddressMap.d.ts +1 -1
  85. package/dist/types/sdk/utils/viem/sendRawTx.d.ts +1 -5
  86. package/package.json +5 -3
  87. package/dist/cjs/abi/310/iSecuritizeDegenNFT.js +0 -263
  88. package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +0 -278
  89. package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +0 -97
  90. package/dist/cjs/sdk/pools/PoolService.js +0 -391
  91. package/dist/esm/abi/310/iSecuritizeDegenNFT.js +0 -239
  92. package/dist/esm/abi/310/iSecuritizeKYCFactory.js +0 -254
  93. package/dist/esm/abi/iStateSerializer.js +0 -12
  94. package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +0 -73
  95. package/dist/esm/sdk/pools/PoolService.js +0 -371
  96. package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +0 -324
  97. package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +0 -322
  98. package/dist/types/abi/iStateSerializer.d.ts +0 -11
  99. package/dist/types/sdk/base/token-types.d.ts +0 -33
  100. package/dist/types/sdk/market/ZapperRegister.d.ts +0 -17
  101. package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +0 -345
  102. package/dist/types/sdk/market/types.d.ts +0 -10
  103. package/dist/types/sdk/pools/PoolService.d.ts +0 -14
  104. /package/dist/cjs/{sdk/market → plugins/zappers}/types.js +0 -0
  105. /package/dist/esm/{sdk/market → plugins/zappers}/types.js +0 -0
@@ -0,0 +1,11 @@
1
+ import { isV310 } from "../constants/index.js";
2
+ import { PoolServiceV310 } from "./PoolServiceV310.js";
3
+ function createPoolService(sdk, version) {
4
+ if (isV310(version)) {
5
+ return new PoolServiceV310(sdk, version);
6
+ }
7
+ throw new Error(`Unsupported Pool Service version ${version}`);
8
+ }
9
+ export {
10
+ createPoolService
11
+ };
@@ -1,2 +1,3 @@
1
- export * from "./PoolService.js";
1
+ export * from "./AbstractPoolService.js";
2
+ export * from "./createPoolService.js";
2
3
  export * from "./types.js";
@@ -14,7 +14,7 @@ class AddressMap {
14
14
  this.#name = name;
15
15
  }
16
16
  /**
17
- * Adds or overwrites value, undefined removes value
17
+ * Adds or updates value, undefined removes value
18
18
  * @param address
19
19
  * @param value
20
20
  */
@@ -1,7 +1,4 @@
1
- import {
2
- estimateGas,
3
- sendTransaction
4
- } from "viem/actions";
1
+ import { sendTransaction } from "viem/actions";
5
2
  import { getAction } from "viem/utils";
6
3
  async function sendRawTx(client, params) {
7
4
  const { tx, ...rest } = params;
@@ -16,21 +13,6 @@ async function sendRawTx(client, params) {
16
13
  value: BigInt(tx.value)
17
14
  });
18
15
  }
19
- async function estimateRawTxGas(client, params) {
20
- const { tx, ...rest } = params;
21
- return getAction(
22
- client,
23
- estimateGas,
24
- "estimateGas"
25
- )({
26
- ...rest,
27
- account: params.account,
28
- data: tx.callData,
29
- to: tx.to,
30
- value: BigInt(tx.value)
31
- });
32
- }
33
16
  export {
34
- estimateRawTxGas,
35
17
  sendRawTx
36
18
  };
@@ -9,6 +9,7 @@ export * from "./EthCallSpy.js";
9
9
  export * from "./isOutOfSyncError.js";
10
10
  export * from "./isRateLimitError.js";
11
11
  export * from "./isTransientError.js";
12
+ export { isRangeError, LogSplitterTransportOptions, logSplitterTransport, } from "./logSplitterTransport.js";
12
13
  export * from "./ltUtils.js";
13
14
  export * from "./migrateFaucet.js";
14
15
  export * from "./mint/index.js";
@@ -0,0 +1,118 @@
1
+ import { type PublicRpcSchema, type Transport } from "viem";
2
+ /** Schema entry for `eth_getLogs` extracted from viem's {@link PublicRpcSchema}. */
3
+ type EthGetLogsSchema = Extract<PublicRpcSchema[number], {
4
+ Method: "eth_getLogs";
5
+ }>;
6
+ /**
7
+ * Filter parameter for `eth_getLogs` as defined by viem's {@link PublicRpcSchema}.
8
+ * A discriminated union of block-range filters and block-hash filters.
9
+ */
10
+ export type EthGetLogsFilter = EthGetLogsSchema["Parameters"][0];
11
+ /** Raw RPC return type for `eth_getLogs` (logs with hex-encoded quantities). */
12
+ export type EthGetLogsResult = EthGetLogsSchema["ReturnType"];
13
+ /**
14
+ * Options controlling pagination behaviour of {@link logSplitterTransport}.
15
+ */
16
+ export interface LogSplitterTransportOptions {
17
+ /**
18
+ * Acts as a min page size hint when there's no explit hint in rpc error message.
19
+ * Has no effect once the page size is already below `softLimit`.
20
+ */
21
+ softLimit?: number;
22
+ /**
23
+ * Initial page size. The block range is walked in `hardLimit`-sized pages
24
+ * from the start without attempting the full range first.
25
+ */
26
+ hardLimit?: number;
27
+ }
28
+ /**
29
+ * @internal
30
+ * Returns `true` when both `fromBlock` and `toBlock` are concrete hex-encoded
31
+ * block numbers and `blockHash` is absent. Only fixed numeric ranges can be
32
+ * split into sub-ranges for pagination.
33
+ *
34
+ * At the RPC transport level, block numbers are always `0x`-prefixed hex
35
+ * strings, while named tags (`"latest"`, `"safe"`, etc.) are plain words.
36
+ * The `0x` prefix check is sufficient to distinguish the two.
37
+ *
38
+ * @param filter - The `eth_getLogs` filter object.
39
+ * @returns Whether the filter describes a fixed, splittable block range.
40
+ */
41
+ export declare function isFixedBlockRange(filter: EthGetLogsFilter): boolean;
42
+ /**
43
+ * Returns `true` when the error message matches known RPC range/size limit
44
+ * patterns. Transient errors (timeouts, rate limits, 5xx) are explicitly
45
+ * excluded — they should be retried by the underlying transport.
46
+ *
47
+ * @param error - Any thrown value.
48
+ * @returns Whether the error indicates a block-range or result-size limit.
49
+ */
50
+ export declare function isRangeError(error: unknown): boolean;
51
+ /**
52
+ * @internal
53
+ * Attempts to extract a concrete page-size hint from an error thrown by an
54
+ * RPC provider. Two strategies are tried:
55
+ *
56
+ * 1. **Alchemy JSON details** — parses the `details` field of a
57
+ * {@link HttpRequestError} for a suggested `[fromHex, toHex]` range and
58
+ * computes the span as `toHex - fromHex + 1`.
59
+ * 2. **Generic N-blocks pattern** — matches `/<number> block(s)/i` in the
60
+ * error message.
61
+ *
62
+ * @param error - Any thrown value.
63
+ * @returns The suggested page size, or `null` if no hint could be extracted.
64
+ */
65
+ export declare function parsePageSizeHint(error: unknown): number | null;
66
+ /**
67
+ * @internal
68
+ * Callback that performs a single `eth_getLogs` RPC call for the given
69
+ * inclusive block range `[from, to]`.
70
+ */
71
+ export type CallRpcFn = (from: number, to: number) => Promise<EthGetLogsResult>;
72
+ /**
73
+ * @internal
74
+ * Fetches logs over `[from, to]` using a sequential linear walk with
75
+ * dynamically adjustable page size. On range errors the page is bisected
76
+ * (optionally capped by {@link LogSplitterTransportOptions.softLimit | softLimit}).
77
+ * Reduced page sizes persist for all subsequent pages in the same call.
78
+ *
79
+ * @param callRpc - Callback that performs a single `eth_getLogs` RPC call.
80
+ * @param from - Inclusive start block number.
81
+ * @param to - Inclusive end block number.
82
+ * @param options - Optional pagination limits.
83
+ * @returns All logs in the requested range, concatenated in order.
84
+ *
85
+ * @throws {@link InvalidParamsRpcError} when `from > to`.
86
+ * @throws The original error when a single-block request fails or the error
87
+ * is not a recognised range error.
88
+ */
89
+ export declare function fetchLogsWithPagination(callRpc: CallRpcFn, from: number, to: number, options?: LogSplitterTransportOptions): Promise<EthGetLogsResult>;
90
+ /**
91
+ * Wraps a viem {@link Transport} to transparently split `eth_getLogs` requests
92
+ * that exceed RPC provider block-range or result-size limits.
93
+ *
94
+ * Only requests with concrete numeric `fromBlock`/`toBlock` values (hex or
95
+ * bigint) are intercepted. Calls using block tags (`"latest"`, `"earliest"`,
96
+ * etc.) or `blockHash` are passed through unmodified.
97
+ *
98
+ * @param transport - The underlying viem transport to wrap.
99
+ * @param options - Optional pagination configuration.
100
+ * @returns A new transport that performs automatic log pagination.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * import { createPublicClient, http } from "viem";
105
+ * import { mainnet } from "viem/chains";
106
+ * import { logSplitterTransport } from "./logSplitterTransport.js";
107
+ *
108
+ * const client = createPublicClient({
109
+ * chain: mainnet,
110
+ * transport: logSplitterTransport(http("https://rpc.example.com"), {
111
+ * hardLimit: 10_000,
112
+ * softLimit: 2_000,
113
+ * }),
114
+ * });
115
+ * ```
116
+ */
117
+ export declare function logSplitterTransport(transport: Transport, logOptions?: LogSplitterTransportOptions): Transport;
118
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { Address } from "viem";
2
+ import type { IGearboxSDKPlugin } from "../../sdk/index.js";
3
+ import { AddressMap, BasePlugin } from "../../sdk/index.js";
4
+ import type { ZapperDataFull, ZapperStateHuman } from "./types.js";
5
+ export interface ZappersPluginState {
6
+ zappers: Record<Address, ZapperDataFull[]>;
7
+ }
8
+ export declare class ZappersPlugin extends BasePlugin<ZappersPluginState> implements IGearboxSDKPlugin<ZappersPluginState> {
9
+ #private;
10
+ constructor(extraZappers?: ZapperDataFull[], loadOnAttach?: boolean);
11
+ load(force?: boolean): Promise<ZappersPluginState>;
12
+ get extraZappers(): AddressMap<ZapperDataFull[]>;
13
+ get zappers(): AddressMap<ZapperDataFull[]>;
14
+ get loaded(): boolean;
15
+ stateHuman(_?: boolean): ZapperStateHuman[];
16
+ get state(): ZappersPluginState;
17
+ hydrate(state: ZappersPluginState): void;
18
+ }
@@ -0,0 +1,6 @@
1
+ import type { NetworkType } from "../../sdk/index.js";
2
+ import type { ZapperDataFull } from "./types.js";
3
+ /**
4
+ * Temporary zappers
5
+ */
6
+ export declare const extraZappers: Partial<Record<NetworkType, ZapperDataFull[]>>;
@@ -0,0 +1,3 @@
1
+ export * from "./extraZappers.js";
2
+ export * from "./types.js";
3
+ export * from "./ZappersPlugin.js";
@@ -0,0 +1,12 @@
1
+ import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
2
+ import type { Address } from "viem";
3
+ import type { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
4
+ import type { BaseContractStateHuman, Unarray } from "../../sdk/index.js";
5
+ export type ZapperData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof peripheryCompressorAbi, "getZappers">["outputs"]>>;
6
+ export interface ZapperDataFull extends ZapperData {
7
+ pool: Address;
8
+ }
9
+ export interface ZapperStateHuman extends BaseContractStateHuman {
10
+ tokenIn: string;
11
+ tokenOut: string;
12
+ }
@@ -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 { CreditSuite, MarketSuite, OnDemandPriceUpdates, UpdatePriceFeedsResult } from "../market/index.js";
5
+ import type { OnDemandPriceUpdates, UpdatePriceFeedsResult } from "../market/index.js";
6
6
  import { type Asset, type RouterCASlice } from "../router/index.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";
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";
9
9
  export interface CreditAccountServiceOptions {
10
10
  batchSize?: number;
11
11
  }
@@ -21,14 +21,6 @@ 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>;
32
24
  /**
33
25
  * Methods to get all credit accounts with some optional filtering
34
26
  * Performs all necessary price feed updates under the hood
@@ -37,31 +29,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
37
29
  * @param blockNumber
38
30
  * @returns returned credit accounts are sorted by health factor in ascending order
39
31
  */
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>>;
32
+ getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountData>>;
65
33
  /**
66
34
  * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
67
35
  Assosiates rewards by adapter + stakedPhantomToken
@@ -136,7 +104,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
136
104
  positive value for debt increase.
137
105
  * @returns All necessary data to execute the transaction (call, credit facade)
138
106
  */
139
- changeDebt({ creditAccount, amount, collateral, }: ChangeDeptProps): Promise<CreditAccountOperationResult>;
107
+ changeDebt({ creditAccount, amount, addCollateral, }: ChangeDeptProps): Promise<CreditAccountOperationResult>;
140
108
  /**
141
109
  * Executes swap specified by given calls, update quotas of affected tokens
142
110
  - Swap is executed in the following order: price update -> execute swap path -> update quotas
@@ -173,25 +141,31 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
173
141
  * @returns
174
142
  */
175
143
  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>;
183
144
  /**
184
145
  * Executes swap specified by given calls, update quotas of affected tokens
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
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}
192
166
  * @returns All necessary data to execute the transaction (call, credit facade)
193
- **/
194
- openCA(props: OpenCAProps): Promise<CreditAccountOperationResult>;
167
+ */
168
+ openCA({ ethAmount, creditManager, collateral, permits, debt, withdrawDebt, referralCode, to, calls: openPathCalls, minQuota, averageQuota, }: OpenCAProps): Promise<CreditAccountOperationResult>;
195
169
  /**
196
170
  * Returns borrow rate with 4 digits precision (10000 = 100%)
197
171
  * @param ca
@@ -203,42 +177,6 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
203
177
  * @param ca
204
178
  */
205
179
  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>;
242
180
  /**
243
181
  * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
244
182
  *
@@ -274,38 +212,4 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
274
212
  private get marketConfigurators();
275
213
  private get rewardCompressor();
276
214
  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}`[]>;
311
215
  }
@@ -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, calls: wrapCalls, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
15
+ repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, tokensToClaim, }: 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 { IPriceUpdateTx, MultiCall, RawTx } from "../types/index.js";
8
+ import type { 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,10 +83,6 @@ 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>;
90
86
  /**
91
87
  * close or zeroDebt
92
88
  */
@@ -267,9 +263,8 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
267
263
  /**
268
264
  * Flag to withdraw debt to wallet after opening credit account;
269
265
  * used for borrowing functionality
270
- * If true, will withdraw underlying token, otherwise will withdraw specified token
271
266
  */
272
- withdrawToken?: boolean | Address;
267
+ withdrawDebt?: boolean;
273
268
  /**
274
269
  * Permits of collateral tokens (in any permittable token is present) {@link PermitResult}
275
270
  */
@@ -279,19 +274,10 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
279
274
  * Used for trading and strategy functionality
280
275
  */
281
276
  calls: Array<MultiCall>;
282
- /**
283
- * Slot for optional call to execute after main tx.
284
- * For example: add bots
285
- */
286
- callsAfter?: Array<MultiCall>;
287
277
  /**
288
278
  * Address of credit manager to open credit account on
289
279
  */
290
280
  creditManager: Address;
291
- /**
292
- * Optional address of credit account to reopen
293
- */
294
- reopenCreditAccount?: Address;
295
281
  /**
296
282
  * Wallet address to transfer credit account to
297
283
  */
@@ -314,13 +300,9 @@ export interface ChangeDeptProps {
314
300
  */
315
301
  amount: bigint;
316
302
  /**
317
- * Assets to add as collateral
303
+ * If true, will add collateral to the credit account
318
304
  */
319
- collateral?: [Asset];
320
- /**
321
- * Assets to wrap
322
- */
323
- wrapAsset?: [Asset];
305
+ addCollateral: boolean;
324
306
  }
325
307
  export interface FullyLiquidateProps {
326
308
  /**
@@ -436,19 +418,6 @@ export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotas
436
418
  */
437
419
  creditAccount: RouterCASlice;
438
420
  }
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
- };
452
421
  export interface ICreditAccountsService extends Construct {
453
422
  sdk: GearboxSDK;
454
423
  /**
@@ -459,41 +428,15 @@ export interface ICreditAccountsService extends Construct {
459
428
  * @returns
460
429
  */
461
430
  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>;
469
431
  /**
470
432
  * Methods to get all credit accounts with some optional filtering
471
433
  * Performs all necessary price feed updates under the hood
472
434
  *
473
435
  * @param options
474
436
  * @param blockNumber
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
437
+ * @returns returned credit accounts are sorted by health factor in ascending order
492
438
  */
493
- loadSpecifiedAccounts(accounts: Address[], priceUpdateTxs: IPriceUpdateTx<{
494
- priceFeed: `0x${string}`;
495
- timestamp: number;
496
- }>[], blockNumber?: bigint): Promise<Array<CreditAccountData>>;
439
+ getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountData>>;
497
440
  /**
498
441
  * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
499
442
  * Assosiates rewards by adapter + stakedPhantomToken
@@ -522,9 +465,9 @@ export interface ICreditAccountsService extends Construct {
522
465
  /**
523
466
  * Generates transaction to liquidate credit account
524
467
  * @param props - {@link FullyLiquidateProps}
525
- * @returns Transaction data and optional loss policy data
468
+ * @returns
526
469
  */
527
- fullyLiquidate(props: FullyLiquidateProps): Promise<FullyLiquidateResult>;
470
+ fullyLiquidate(props: FullyLiquidateProps): Promise<CloseCreditAccountResult>;
528
471
  /**
529
472
  * Closes credit account or closes credit account and keeps it open with zero debt.
530
473
  * - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
@@ -587,13 +530,6 @@ export interface ICreditAccountsService extends Construct {
587
530
  * @returns
588
531
  */
589
532
  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>;
597
533
  /**
598
534
  * Executes swap specified by given calls, update quotas of affected tokens
599
535
  * - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
@@ -638,42 +574,6 @@ export interface ICreditAccountsService extends Construct {
638
574
  * @returns
639
575
  */
640
576
  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>;
677
577
  /**
678
578
  * Withdraws a single collateral from credit account to wallet to and updates quotas;
679
579
  * technically can withdraw several tokens at once