@gearbox-protocol/sdk 16.0.0-next.56 → 16.0.0-next.58

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 (58) hide show
  1. package/dist/cjs/dev/abi.js +99 -16
  2. package/dist/cjs/dev/claimFromFaucet.js +3 -3
  3. package/dist/cjs/dev/index.js +1 -1
  4. package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +2 -2
  5. package/dist/cjs/onchain/accounts/intents/open-strategy.js +38 -4
  6. package/dist/cjs/onchain/base/TokensMeta.js +3 -3
  7. package/dist/cjs/onchain/chain/chains.js +7 -0
  8. package/dist/cjs/onchain/market/strategyName.js +1 -1
  9. package/dist/cjs/sdk/execute/ExecuteApi.js +1 -0
  10. package/dist/cjs/sdk/index.js +2 -0
  11. package/dist/cjs/sdk/prepare/PrepareApi.js +18 -1
  12. package/dist/cjs/sdk/prepare/errors.js +21 -0
  13. package/dist/cjs/sdk/prepare/index.js +2 -0
  14. package/dist/esm/dev/AccountOpener.js +1 -1
  15. package/dist/esm/dev/abi.js +99 -16
  16. package/dist/esm/dev/claimFromFaucet.js +4 -4
  17. package/dist/esm/dev/index.js +2 -2
  18. package/dist/esm/dev/withdrawalUtils.js +1 -1
  19. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +4 -4
  20. package/dist/esm/onchain/accounts/intents/open-strategy.js +38 -4
  21. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  22. package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  23. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  24. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  25. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  26. package/dist/esm/onchain/base/TokensMeta.js +6 -6
  27. package/dist/esm/onchain/chain/chains.js +7 -0
  28. package/dist/esm/onchain/core/createAddressProvider.js +1 -1
  29. package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  30. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  31. package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
  32. package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
  33. package/dist/esm/onchain/market/strategyName.js +1 -1
  34. package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
  35. package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
  36. package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
  37. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  38. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  39. package/dist/esm/sdk/execute/ExecuteApi.js +1 -0
  40. package/dist/esm/sdk/index.js +2 -2
  41. package/dist/esm/sdk/prepare/PrepareApi.js +19 -2
  42. package/dist/esm/sdk/prepare/errors.js +20 -1
  43. package/dist/esm/sdk/prepare/index.js +2 -2
  44. package/dist/types/dev/abi.d.ts +91 -15
  45. package/dist/types/dev/index.d.ts +2 -2
  46. package/dist/types/model/primitives.d.ts +1 -1
  47. package/dist/types/onchain/accounts/intents/open-strategy.d.ts +34 -3
  48. package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
  49. package/dist/types/onchain/accounts/types.d.ts +2 -1
  50. package/dist/types/onchain/base/TokensMeta.d.ts +3 -3
  51. package/dist/types/onchain/base/token-types.d.ts +1 -1
  52. package/dist/types/onchain/market/strategyName.d.ts +1 -1
  53. package/dist/types/sdk/index.d.ts +2 -2
  54. package/dist/types/sdk/prepare/PrepareApi.d.ts +2 -2
  55. package/dist/types/sdk/prepare/errors.d.ts +25 -1
  56. package/dist/types/sdk/prepare/index.d.ts +2 -2
  57. package/dist/types/sdk/prepare/types.d.ts +25 -2
  58. package/package.json +1 -1
@@ -4,11 +4,19 @@ import "../../../model/index.js";
4
4
  import { Asset } from "../../base/types.js";
5
5
  import { MultiCall } from "../../types/transactions.js";
6
6
  import { OnchainSDK } from "../../OnchainSDK.js";
7
- import { SimulationPrices } from "./types.js";
7
+ import { CreditAccountSlice, SimulationPrices } from "./types.js";
8
8
  import "../../index.js";
9
9
  import { Address } from "viem";
10
10
  //#region src/onchain/accounts/intents/open-strategy.d.ts
11
- interface OpenStrategyProps {
11
+ /**
12
+ * Opening an account and putting a position on it in one transaction.
13
+ *
14
+ * The union says which of the two openings this is: {@link OpenStrategyEmpty}
15
+ * takes only the market, because an account holding nothing has nothing to
16
+ * route, no leverage to reach and no target to reach it in.
17
+ */
18
+ type OpenStrategyProps = OpenStrategyFunded | OpenStrategyEmpty;
19
+ interface OpenStrategyFunded {
12
20
  sdk: OnchainSDK;
13
21
  /** Credit manager to open the account in. */
14
22
  creditManager: Address;
@@ -24,6 +32,20 @@ interface OpenStrategyProps {
24
32
  quotaReserve: number | undefined;
25
33
  /** Balances to leave unswapped; everything else is routed into the target. */
26
34
  leftoverBalances?: Asset[];
35
+ /**
36
+ * Existing credit account to put the position on, instead of opening one.
37
+ *
38
+ * Must carry no debt and no quotas. Growing a position that already exists
39
+ * is what the `DEPOSIT` intent is for.
40
+ **/
41
+ creditAccount?: CreditAccountSlice;
42
+ empty?: false;
43
+ }
44
+ /** Opening an account that holds nothing, for a position to land on later. */
45
+ interface OpenStrategyEmpty {
46
+ sdk: OnchainSDK;
47
+ creditManager: Address;
48
+ empty: true;
27
49
  }
28
50
  /**
29
51
  * Projected result of opening a brand-new leveraged position.
@@ -49,6 +71,15 @@ interface OpenStrategyState extends Omit<AccountProjection, "assets" | "quotas">
49
71
  minQuota: Asset[];
50
72
  /** Router path; feeds `openCA.calls`. */
51
73
  calls: MultiCall[];
74
+ /**
75
+ * The account this opening was simulated against and must be executed on,
76
+ * when it reuses one; `undefined` for an opening that creates its own.
77
+ *
78
+ * Carried here rather than asked of the caller again at `buildTx`, so the
79
+ * transaction cannot be built against an account the numbers were not
80
+ * computed for.
81
+ **/
82
+ creditAccount?: Address;
52
83
  }
53
84
  /**
54
85
  * Builds the state opening a leveraged position out of wallet collateral would
@@ -64,4 +95,4 @@ interface OpenStrategyState extends Omit<AccountProjection, "assets" | "quotas">
64
95
  */
65
96
  declare function buildOpenStrategyState(props: OpenStrategyProps): Promise<OpenStrategyState>;
66
97
  //#endregion
67
- export { OpenStrategyProps, OpenStrategyState, buildOpenStrategyState };
98
+ export { OpenStrategyEmpty, OpenStrategyFunded, OpenStrategyProps, OpenStrategyState, buildOpenStrategyState };
@@ -1,6 +1,6 @@
1
1
  import { Asset } from "../../../base/types.js";
2
2
  import { OnchainSDK } from "../../../OnchainSDK.js";
3
- import { OpenStrategyProps } from "../open-strategy.js";
3
+ import { OpenStrategyFunded } from "../open-strategy.js";
4
4
  import "../../../index.js";
5
5
  import { MarketSdkExtras } from "../testing/market.js";
6
6
  import { Address } from "viem";
@@ -51,6 +51,6 @@ declare const case_underlying_1x: OpenStrategyCase;
51
51
  */
52
52
  declare const case_mixed_with_leftover: OpenStrategyCase;
53
53
  declare function buildOpenStrategySdk(extras?: MarketSdkExtras): OnchainSDK;
54
- declare function buildOpenStrategyProps(c: OpenStrategyCase, sdk: OnchainSDK): OpenStrategyProps;
54
+ declare function buildOpenStrategyProps(c: OpenStrategyCase, sdk: OnchainSDK): OpenStrategyFunded;
55
55
  //#endregion
56
56
  export { COLLATERAL_ANY, HALF_UND, KEEP_ANY, LEVERAGE_1X, LEVERAGE_2X, LEVERAGE_3X, LT, MARGIN_UND, OpenStrategyCase, buildOpenStrategyProps, buildOpenStrategySdk, case_mixed_with_leftover, case_underlying_1x, case_underlying_3x, quotaFor };
@@ -214,7 +214,8 @@ interface OpenCAProps extends PrepareUpdateQuotasProps {
214
214
  */
215
215
  creditManager: Address;
216
216
  /**
217
- * Optional address of credit account to reopen
217
+ * Optional address of an existing credit account to run the opening on,
218
+ * instead of opening a new one.
218
219
  */
219
220
  reopenCreditAccount?: Address;
220
221
  /**
@@ -22,7 +22,7 @@ interface FormatBNOptions {
22
22
  }
23
23
  /**
24
24
  * Source, target, and phantom token of a delayed redemption, used to rewrite
25
- * the phantom's display symbol as `"source -> target"`.
25
+ * the phantom's display symbol as `"target redemption from source"`.
26
26
  **/
27
27
  interface RedemptionPhantomRename {
28
28
  /**
@@ -72,7 +72,7 @@ declare class TokensMeta extends AddressMap<TokenMetaData> {
72
72
  * Returns the display symbol for a token.
73
73
  *
74
74
  * This is not always the on-chain ERC-20 `symbol()`: curated pretty names
75
- * and redemption phantom tokens (`"source -> target"`) replace it.
75
+ * and redemption phantom tokens (`"target redemption from source"`) replace it.
76
76
  *
77
77
  * @param token - Token address.
78
78
  * @throws If the token is not in the registry.
@@ -133,7 +133,7 @@ declare class TokensMeta extends AddressMap<TokenMetaData> {
133
133
  unwrapRWA(token: Address): Address;
134
134
  /**
135
135
  * Rewrites display symbols of redemption phantom tokens to
136
- * `"${source} -> ${target}"`.
136
+ * `"${target} redemption from ${source}"`.
137
137
  *
138
138
  * @param renames - Phantom / source / target address triples.
139
139
  **/
@@ -19,7 +19,7 @@ declare const NON_STRATEGY_PHANTOM_TOKEN_TYPES: readonly ["PHANTOM_TOKEN::INFINI
19
19
  * Token metadata stored in {@link TokensMeta}.
20
20
  *
21
21
  * `symbol` is a display ticker. The SDK may rewrite it (curated pretty names,
22
- * `"source -> target"` for redemption phantom tokens) and it is not guaranteed
22
+ * `"target redemption from source"` for redemption phantom tokens) and it is not guaranteed
23
23
  * to match the ERC-20 `symbol()` on chain.
24
24
  */
25
25
  interface SimpleTokenMeta extends TokenData {
@@ -6,7 +6,7 @@ import "../../model/index.js";
6
6
  * borrowed underlying, e.g. `"wstETH / WETH"`.
7
7
  *
8
8
  * Uses each token's display {@link Token.symbol}, which may already be a
9
- * curated pretty name or a `"source -> target"` redemption rewrite.
9
+ * curated pretty name or a `"target redemption from source"` redemption rewrite.
10
10
  *
11
11
  * @param target - Collateral the position is built around.
12
12
  * @param underlying - Token the position borrows.
@@ -3,7 +3,7 @@ import { LeverageBand } from "../onchain/accounts/intents/leverage-band.js";
3
3
  import { OperationState, PathLossRate, WithdrawCeilings } from "../onchain/accounts/intents/types.js";
4
4
  import { IAnalytics, IAnalyticsByMode } from "./analytics/types.js";
5
5
  import { ILiquidations, ILiquidationsByMode } from "./liquidations/types.js";
6
- import { AccountFlowError, CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, toRefusalError, unexpectedFailure } from "./prepare/errors.js";
6
+ import { AccountFlowError, CreditAccountNotEmptyError, CreditAccountNotFoundError, DebtOutOfRangeError, EmptyOpenTakesNothingError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, emptyOpenTakesNothing, noStrategyTargetCollateral, toRefusalError, unexpectedFailure } from "./prepare/errors.js";
7
7
  import { AddCollateralParams, AdjustLeverageParams, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
8
8
  import { ChainOf, PrepareApi } from "./prepare/PrepareApi.js";
9
9
  import "./prepare/index.js";
@@ -38,4 +38,4 @@ import { SourceUnavailableError } from "./errors/SourceUnavailableError.js";
38
38
  import { assertSameChains } from "./errors/assertSameChains.js";
39
39
  import { everyChainFailed } from "./errors/everyChainFailed.js";
40
40
  import "./errors/index.js";
41
- export { AbstractNamespace, AccountFlowError, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, AnalyticsNamespace, BorrowLimitBinding, ChainOf, ChainRef, CreditAccountNotFoundError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DebtOutOfRangeError, DelayedStrategyResult, DepositStrategyParams, EnsureFreshChains, type EntityMerger, ExecuteApi, type FilterResult, FinalizeParams, FinalizeResult, ForbiddenTokenError, GearboxSDK, GearboxSDKOptions, IAnalytics, IAnalyticsByMode, IGearboxSDK, ILiquidations, ILiquidationsByMode, INotices, INoticesByMode, IOpportunities, IOpportunitiesBase, IOpportunitiesByMode, IOpportunitiesExecute, IOpportunitiesOffchainBranch, IOpportunitiesOffchainOnly, IOpportunitiesOnchainBranch, IOpportunitiesOnchainOnly, IOpportunitiesPrepare, IOpportunityMergers, IPositionMergers, IPositions, IPositionsBase, IPositionsByMode, IPositionsOffchainBranch, IPositionsOffchainOnly, IPositionsOnchainBranch, IPositionsOnchainOnly, IPreview, IPreviewByMode, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, IntentPreviewError, type LeverageBand, LeverageOutOfRangeError, LiquidationsNamespace, type ListMerger, LpParams, LpRedeemParams, LpResult, LpState, MalformedTransactionError, MarketExpiredError, MarketPausedError, type MergeListResult, MergedQuery, MissingSourceError, Mode, MultipleDelayedWithdrawalsError, NamespaceOptions, NoDelayedRouteError, NoRecordedIntentError, NoSourceServedError, NoStrategyTargetCollateralError, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenFlowError, OpenPrepareRequest, OpenStrategyParams, OpenStrategyResult, type OperationState, OpportunitiesNamespace, type PathLossRate, PlainMultichainSDKOptions, PoolInput, PoolPrepareRequest, PoolSunsetError, PositionInput, PositionsNamespace, PrepareApi, PrepareOptions, PrepareRequest, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewNamespace, PreviewRefusal, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, RepayStrategyParams, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyResult, StrategyRoutesResult, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, WithdrawalInProgressError, assertSameChains, creditAccountNotFound, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, raise, refuse, toRefusalError, unexpectedFailure };
41
+ export { AbstractNamespace, AccountFlowError, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, AnalyticsNamespace, BorrowLimitBinding, ChainOf, ChainRef, CreditAccountNotEmptyError, CreditAccountNotFoundError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DebtOutOfRangeError, DelayedStrategyResult, DepositStrategyParams, EmptyOpenTakesNothingError, EnsureFreshChains, type EntityMerger, ExecuteApi, type FilterResult, FinalizeParams, FinalizeResult, ForbiddenTokenError, GearboxSDK, GearboxSDKOptions, IAnalytics, IAnalyticsByMode, IGearboxSDK, ILiquidations, ILiquidationsByMode, INotices, INoticesByMode, IOpportunities, IOpportunitiesBase, IOpportunitiesByMode, IOpportunitiesExecute, IOpportunitiesOffchainBranch, IOpportunitiesOffchainOnly, IOpportunitiesOnchainBranch, IOpportunitiesOnchainOnly, IOpportunitiesPrepare, IOpportunityMergers, IPositionMergers, IPositions, IPositionsBase, IPositionsByMode, IPositionsOffchainBranch, IPositionsOffchainOnly, IPositionsOnchainBranch, IPositionsOnchainOnly, IPreview, IPreviewByMode, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, IntentPreviewError, type LeverageBand, LeverageOutOfRangeError, LiquidationsNamespace, type ListMerger, LpParams, LpRedeemParams, LpResult, LpState, MalformedTransactionError, MarketExpiredError, MarketPausedError, type MergeListResult, MergedQuery, MissingSourceError, Mode, MultipleDelayedWithdrawalsError, NamespaceOptions, NoDelayedRouteError, NoRecordedIntentError, NoSourceServedError, NoStrategyTargetCollateralError, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenFlowError, OpenPrepareRequest, OpenStrategyParams, OpenStrategyResult, type OperationState, OpportunitiesNamespace, type PathLossRate, PlainMultichainSDKOptions, PoolInput, PoolPrepareRequest, PoolSunsetError, PositionInput, PositionsNamespace, PrepareApi, PrepareOptions, PrepareRequest, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewNamespace, PreviewRefusal, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, RepayStrategyParams, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyResult, StrategyRoutesResult, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, WithdrawalInProgressError, assertSameChains, creditAccountNotEmpty, creditAccountNotFound, emptyOpenTakesNothing, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, raise, refuse, toRefusalError, unexpectedFailure };
@@ -9,7 +9,7 @@ import { MultichainConstruct } from "../../onchain/base/MultichainConstruct.js";
9
9
  import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
10
10
  import { WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
11
11
  import "../../onchain/index.js";
12
- import { AccountFlowError, DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
12
+ import { AccountFlowError, CreditAccountNotEmptyError, CreditAccountNotFoundError, DebtOutOfRangeError, EmptyOpenTakesNothingError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
13
13
  import { AddCollateralParams, AdjustLeverageParams, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
14
14
  import { EnsureFreshChains } from "../types.js";
15
15
  import { Address } from "viem";
@@ -65,7 +65,7 @@ declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPr
65
65
  /**
66
66
  * {@inheritDoc IOpportunitiesPrepare.openNewStrategy}
67
67
  **/
68
- openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError>>;
68
+ openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError | EmptyOpenTakesNothingError | CreditAccountNotFoundError | CreditAccountNotEmptyError>>;
69
69
  /**
70
70
  * {@inheritDoc IOpportunitiesPrepare.depositStrategy}
71
71
  **/
@@ -232,6 +232,22 @@ interface CreditAccountNotFoundError extends IGearboxError {
232
232
  code: "creditAccountNotFound";
233
233
  creditAccount: Address;
234
234
  }
235
+ /**
236
+ * The account named to open a position on carries debt or quotas.
237
+ *
238
+ * Growing a position that already exists is `depositStrategy`.
239
+ **/
240
+ interface CreditAccountNotEmptyError extends IGearboxError {
241
+ code: "creditAccountNotEmpty";
242
+ creditAccount: Address;
243
+ }
244
+ /**
245
+ * An empty opening was asked for with something to open it with: collateral to
246
+ * spend, an account to reuse, or a leverage to reach.
247
+ **/
248
+ interface EmptyOpenTakesNothingError extends IGearboxError {
249
+ code: "emptyOpenTakesNothing";
250
+ }
235
251
  /**
236
252
  * The SDK could not answer at all: a read that failed, a chain it is not
237
253
  * connected to, a market or token address it knows nothing about, a contract
@@ -304,10 +320,18 @@ declare function toRefusalError<I extends PreviewIssue>(issue: I): RefusalErrors
304
320
  * {@inheritDoc NoStrategyTargetCollateralError}
305
321
  **/
306
322
  declare function noStrategyTargetCollateral(creditManager: Address): NoStrategyTargetCollateralError;
323
+ /**
324
+ * {@inheritDoc CreditAccountNotEmptyError}
325
+ **/
326
+ declare function creditAccountNotEmpty(creditAccount: Address): CreditAccountNotEmptyError;
307
327
  /**
308
328
  * {@inheritDoc CreditAccountNotFoundError}
309
329
  **/
310
330
  declare function creditAccountNotFound(creditAccount: Address): CreditAccountNotFoundError;
331
+ /**
332
+ * {@inheritDoc EmptyOpenTakesNothingError}
333
+ **/
334
+ declare function emptyOpenTakesNothing(): EmptyOpenTakesNothingError;
311
335
  /**
312
336
  * {@inheritDoc UnexpectedFailureError}
313
337
  *
@@ -316,4 +340,4 @@ declare function creditAccountNotFound(creditAccount: Address): CreditAccountNot
316
340
  **/
317
341
  declare function unexpectedFailure(thrown: unknown): UnexpectedFailureError;
318
342
  //#endregion
319
- export { AccountFlowError, CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, toRefusalError, unexpectedFailure };
343
+ export { AccountFlowError, CreditAccountNotEmptyError, CreditAccountNotFoundError, DebtOutOfRangeError, EmptyOpenTakesNothingError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, emptyOpenTakesNothing, noStrategyTargetCollateral, toRefusalError, unexpectedFailure };
@@ -1,7 +1,7 @@
1
1
  import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, raise, refuse } from "../../onchain/validation/refusal.js";
2
2
  import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
3
3
  import { OperationState, PathLossRate, WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
4
- import { AccountFlowError, CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, toRefusalError, unexpectedFailure } from "./errors.js";
4
+ import { AccountFlowError, CreditAccountNotEmptyError, CreditAccountNotFoundError, DebtOutOfRangeError, EmptyOpenTakesNothingError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, emptyOpenTakesNothing, noStrategyTargetCollateral, toRefusalError, unexpectedFailure } from "./errors.js";
5
5
  import { AddCollateralParams, AdjustLeverageParams, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
6
6
  import { ChainOf, PrepareApi } from "./PrepareApi.js";
7
- export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding, ChainOf, CreditAccountNotFoundError, DebtOutOfRangeError, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, ForbiddenTokenError, IOpportunitiesPrepare, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, IntentPreviewError, type LeverageBand, LeverageOutOfRangeError, LpParams, LpRedeemParams, LpResult, LpState, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, PoolSunsetError, PositionInput, PrepareApi, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, raise, refuse, toRefusalError, unexpectedFailure };
7
+ export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding, ChainOf, CreditAccountNotEmptyError, CreditAccountNotFoundError, DebtOutOfRangeError, DelayedStrategyResult, DepositStrategyParams, EmptyOpenTakesNothingError, FinalizeParams, FinalizeResult, ForbiddenTokenError, IOpportunitiesPrepare, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, IntentPreviewError, type LeverageBand, LeverageOutOfRangeError, LpParams, LpRedeemParams, LpResult, LpState, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, PoolSunsetError, PositionInput, PrepareApi, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, emptyOpenTakesNothing, noStrategyTargetCollateral, raise, refuse, toRefusalError, unexpectedFailure };
@@ -14,7 +14,7 @@ import { AccountCalculatorOperation } from "../../onchain/accounts/intents/opera
14
14
  import { ClaimRemainder, DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteRefusals, WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
15
15
  import { OpenStrategyState } from "../../onchain/accounts/intents/open-strategy.js";
16
16
  import "../../onchain/index.js";
17
- import { AccountFlowError, DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
17
+ import { AccountFlowError, CreditAccountNotEmptyError, CreditAccountNotFoundError, DebtOutOfRangeError, EmptyOpenTakesNothingError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
18
18
  import { Address } from "viem";
19
19
  //#region src/sdk/prepare/types.d.ts
20
20
  /**
@@ -332,6 +332,29 @@ interface OpenStrategyParams extends PrepareOptions {
332
332
  targetToken?: Address;
333
333
  /** Collateral to leave unswapped; everything else is routed into the target. */
334
334
  leftoverBalances?: Asset[];
335
+ /**
336
+ * Existing credit account to open the position on, instead of creating one.
337
+ *
338
+ * Must belong to `strategy.creditManager` and carry no debt and no quotas —
339
+ * an account pre-opened by an {@link empty} opening.
340
+ * The projection is identical either way; only the transaction differs, and
341
+ * `execute.buildTx` reads which one to build off the result's own
342
+ * `state.creditAccount`.
343
+ **/
344
+ creditAccount?: Address;
345
+ /**
346
+ * Open the account holding nothing: no collateral, no debt, no quotas, and no
347
+ * route quoted. A wallet holds one so a position can be put on it later, by
348
+ * an opening that names it as {@link creditAccount}.
349
+ *
350
+ * {@link collateral} must be empty, {@link leverage} zero and
351
+ * {@link creditAccount} unset — the flag and the arguments have to agree.
352
+ * Neither leverage nor {@link targetToken} is read: with no collateral the
353
+ * debt is zero at any leverage, and there is nothing to route anywhere. Zero
354
+ * is the one leverage an ordinary opening refuses, so it cannot be mistaken
355
+ * for a request.
356
+ **/
357
+ empty?: boolean;
335
358
  }
336
359
  interface LpParams {
337
360
  /**
@@ -438,7 +461,7 @@ interface IOpportunitiesPrepare {
438
461
  * The one flow with no account yet, so the result carries no operation list —
439
462
  * it feeds `sdk.accounts.openCA` instead.
440
463
  **/
441
- openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError>>;
464
+ openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError | EmptyOpenTakesNothingError | CreditAccountNotFoundError | CreditAccountNotEmptyError>>;
442
465
  /**
443
466
  * Growing a position: collateral in, debt drawn on top, both converted into
444
467
  * the position token.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "16.0.0-next.56",
3
+ "version": "16.0.0-next.58",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {