@gearbox-protocol/sdk 13.3.3 → 13.4.0-beta.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.
@@ -2,9 +2,9 @@ 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 { PriceUpdateV310, UpdatePriceFeedsResult } from "../market/index.js";
6
6
  import { type Asset, type RouterCASlice } from "../router/index.js";
7
- import type { MultiCall } from "../types/index.js";
7
+ import type { MultiCall, RawTx } from "../types/index.js";
8
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;
@@ -177,30 +177,52 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
177
177
  * @param ca
178
178
  */
179
179
  getOptimalHFForPartialLiquidation(ca: CreditAccountData): bigint;
180
- /**
181
- * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
182
- *
183
- * This can be used by batch liquidator
184
- * @param accounts
185
- * @returns
186
- */
187
- getUpdateForAccounts(accounts: Array<RouterCASlice>): Promise<UpdatePriceFeedsResult>;
188
180
  protected getUpdateForAccount(options: PriceUpdatesOptions): Promise<UpdatePriceFeedsResult>;
189
181
  /**
190
182
  * Returns account price updates that can be used in credit facade multicall or liquidator calls
191
183
  * @param options
192
184
  * @returns
193
185
  */
194
- getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<OnDemandPriceUpdates>;
186
+ getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<PriceUpdateV310[]>;
195
187
  /**
196
- * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
197
- * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
198
- * - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
199
- * - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
200
- * @param acc
201
- * @returns
188
+ * Analyzes a multicall array and prepends necessary on-demand price feed updates.
189
+ *
190
+ * Deduplicates existing `onDemandPriceUpdates` calls
191
+ *
192
+ * @param creditManager - Address of the credit manager
193
+ * @param calls - The multicall array to prepend price updates to
194
+ * @param ca - Credit account slice, undefined when opening a new account
195
+ * @param options - Optional settings for price update generation
196
+ * @returns A new array with a single consolidated price update call prepended,
197
+ * followed by the non-price-update calls in their original order
198
+ */
199
+ protected prependPriceUpdates(creditManager: Address, calls: MultiCall[], ca?: RouterCASlice, options?: {
200
+ ignoreReservePrices?: boolean;
201
+ }): Promise<MultiCall[]>;
202
+ /**
203
+ * Executes a multicall on a credit account, automatically prepending
204
+ * necessary on-demand price feed updates.
205
+ *
206
+ * @param creditAccount - Credit account to execute multicall on
207
+ * @param calls - Array of multicall operations (price updates will be inferred)
208
+ * @param options - Optional settings for price update generation
209
+ * @returns Raw transaction ready to be signed and sent
202
210
  */
203
- getPriceUpdatesForFacade(options: PriceUpdatesOptions): Promise<Array<MultiCall>>;
211
+ multicall(creditAccount: RouterCASlice, calls: MultiCall[], options?: {
212
+ ignoreReservePrices?: boolean;
213
+ }): Promise<RawTx>;
214
+ /**
215
+ * Executes a bot multicall on a credit account, automatically prepending
216
+ * necessary on-demand price feed updates.
217
+ *
218
+ * @param creditAccount - Credit account to execute bot multicall on
219
+ * @param calls - Array of multicall operations (price updates will be inferred)
220
+ * @param options - Optional settings for price update generation
221
+ * @returns Raw transaction ready to be signed and sent
222
+ */
223
+ botMulticall(creditAccount: RouterCASlice, calls: MultiCall[], options?: {
224
+ ignoreReservePrices?: boolean;
225
+ }): Promise<RawTx>;
204
226
  protected prepareDisableQuotas(ca: RouterCASlice): Array<MultiCall>;
205
227
  protected prepareUpdateQuotas(creditFacade: Address, { averageQuota, minQuota }: PrepareUpdateQuotasProps): Array<MultiCall>;
206
228
  protected prepareDecreaseDebt(ca: RouterCASlice): Array<MultiCall>;
@@ -0,0 +1,39 @@
1
+ import type { PriceUpdateV310 } from "../market/pricefeeds/types.js";
2
+ import type { MultiCall } from "../types/index.js";
3
+ import { AddressSet } from "../utils/AddressSet.js";
4
+ /**
5
+ * Splits a multicall array into existing price-update data and remaining calls.
6
+ *
7
+ * All `onDemandPriceUpdates` entries are decoded and their {@link PriceUpdate}
8
+ * tuples are collected into a flat array. The remaining (non-price-update)
9
+ * calls are returned in their original order.
10
+ *
11
+ * @param calls - Array of multicall entries to split
12
+ * @returns Object with `priceUpdates` (decoded price update tuples) and
13
+ * `remainingCalls` (everything else, preserving order)
14
+ */
15
+ export declare function extractPriceUpdates(calls: MultiCall[]): {
16
+ priceUpdates: PriceUpdateV310[];
17
+ remainingCalls: MultiCall[];
18
+ };
19
+ /**
20
+ * Extracts token addresses from `updateQuota` calls that have a positive `quotaChange`.
21
+ *
22
+ * Only tokens whose quota is being increased (i.e. `quotaChange > 0`) are
23
+ * returned, since those are the tokens that require fresh price feed data.
24
+ *
25
+ * @param calls - Array of multicall entries to scan
26
+ * @returns Unique token addresses from positive-change quota updates
27
+ */
28
+ export declare function extractQuotaTokens(calls: MultiCall[]): AddressSet;
29
+ /**
30
+ * Merges two {@link PriceUpdate} arrays, deduplicating by `priceFeed` address.
31
+ *
32
+ * When both arrays contain an update for the same price feed, the entry from
33
+ * `existing` takes priority (the caller explicitly included it).
34
+ *
35
+ * @param existing - Price updates already present in the multicall
36
+ * @param generated - Newly generated price updates to merge in
37
+ * @returns Merged array with no duplicate `priceFeed` addresses
38
+ */
39
+ export declare function mergePriceUpdates(existing: PriceUpdateV310[], generated: PriceUpdateV310[]): PriceUpdateV310[];
@@ -3,7 +3,7 @@ import type { creditAccountCompressorAbi } from "../../abi/compressors/creditAcc
3
3
  import type { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompressorV310.js";
4
4
  import type { ConnectedBotData, Construct, CreditAccountData } from "../base/index.js";
5
5
  import type { GearboxSDK } from "../GearboxSDK.js";
6
- import type { CreditSuite, OnDemandPriceUpdates, UpdatePriceFeedsResult } from "../market/index.js";
6
+ import type { CreditSuite, PriceUpdateV310 } from "../market/index.js";
7
7
  import type { Asset, CreditAccountTokensSlice, RouterCASlice, RouterCloseResult } from "../router/index.js";
8
8
  import type { MultiCall, RawTx } from "../types/index.js";
9
9
  export type GetCreditAccountsArgs = ContractFunctionArgs<typeof creditAccountCompressorAbi, "pure" | "view", "getCreditAccounts">;
@@ -554,26 +554,36 @@ export interface ICreditAccountsService extends Construct {
554
554
  * @param ca
555
555
  */
556
556
  getOptimalHFForPartialLiquidation(ca: CreditAccountData): bigint;
557
- /**
558
- * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
559
- *
560
- * This can be used by batch liquidator
561
- * @param accounts
562
- * @returns
563
- */
564
- getUpdateForAccounts(accounts: Array<RouterCASlice>): Promise<UpdatePriceFeedsResult>;
565
557
  /**
566
558
  * Returns account price updates that can be used in credit facade multicall or liquidator calls
567
559
  * @param options
568
560
  * @returns
569
561
  */
570
- getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<OnDemandPriceUpdates>;
562
+ getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<PriceUpdateV310[]>;
571
563
  /**
572
- * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
573
- * @param options
574
- * @returns
564
+ * Executes a multicall on a credit account, automatically prepending
565
+ * necessary on-demand price feed updates inferred from the calls array.
566
+ *
567
+ * @param creditAccount - Credit account to execute multicall on
568
+ * @param calls - Array of multicall operations (price updates will be inferred)
569
+ * @param options - Optional settings for price update generation
570
+ * @returns Raw transaction ready to be signed and sent
575
571
  */
576
- getPriceUpdatesForFacade(options: PriceUpdatesOptions): Promise<Array<MultiCall>>;
572
+ multicall(creditAccount: RouterCASlice, calls: Array<MultiCall>, options?: {
573
+ ignoreReservePrices?: boolean;
574
+ }): Promise<RawTx>;
575
+ /**
576
+ * Executes a bot multicall on a credit account, automatically prepending
577
+ * necessary on-demand price feed updates inferred from the calls array.
578
+ *
579
+ * @param creditAccount - Credit account to execute bot multicall on
580
+ * @param calls - Array of multicall operations (price updates will be inferred)
581
+ * @param options - Optional settings for price update generation
582
+ * @returns Raw transaction ready to be signed and sent
583
+ */
584
+ botMulticall(creditAccount: RouterCASlice, calls: Array<MultiCall>, options?: {
585
+ ignoreReservePrices?: boolean;
586
+ }): Promise<RawTx>;
577
587
  /**
578
588
  * Withdraws a single collateral from credit account to wallet to and updates quotas;
579
589
  * technically can withdraw several tokens at once
@@ -14,6 +14,7 @@ export declare class CreditFacadeV310Contract extends CreditFacadeV310BaseContra
14
14
  liquidateCreditAccount(ca: Address, to: Address, calls: MultiCall[], lossPolicyData?: Hex): RawTx;
15
15
  closeCreditAccount(ca: Address, calls: MultiCall[]): RawTx;
16
16
  multicall(ca: Address, calls: MultiCall[]): RawTx;
17
+ botMulticall(ca: Address, calls: MultiCall[]): RawTx;
17
18
  openCreditAccount(to: Address, calls: MultiCall[], referralCode: bigint): RawTx;
18
19
  }
19
20
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "13.3.3",
3
+ "version": "13.4.0-beta.1",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -103,6 +103,7 @@
103
103
  "tsx": "^4.21.0",
104
104
  "typescript": "^5.9.3",
105
105
  "viem-deal": "^2.0.4",
106
+ "vite": "^8.0.3",
106
107
  "vitest": "^4.1.2"
107
108
  },
108
109
  "peerDependencies": {