@gearbox-protocol/sdk 3.0.0-vfour.13 → 3.0.0-vfour.15

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.
@@ -13216,6 +13216,7 @@ var CreditAccountsService = class extends SDKConstruct {
13216
13216
  functionName: "getCreditAccountData",
13217
13217
  args: [account],
13218
13218
  blockNumber
13219
+ // TODO: we should cache price updates for block to speed up optimistic liquidator
13219
13220
  });
13220
13221
  } catch (e) {
13221
13222
  return void 0;
@@ -13305,19 +13306,12 @@ var CreditAccountsService = class extends SDKConstruct {
13305
13306
  */
13306
13307
  async fullyLiquidate(account, to, slippage = 50n) {
13307
13308
  const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
13308
- const market = this.sdk.marketRegister.findByCreditManager(
13309
- account.creditManager
13310
- );
13311
13309
  const preview = await this.sdk.router.findBestClosePath(
13312
13310
  account,
13313
13311
  cm.creditManager,
13314
13312
  slippage
13315
13313
  );
13316
- const priceUpdates = await this.#getUpdateForAccounts([account]);
13317
- const priceUpdateCalls = market.priceOracle.onDemandPriceUpdates(
13318
- cm.creditFacade.address,
13319
- priceUpdates
13320
- );
13314
+ const priceUpdates = await this.getPriceUpdatesForFacade(account);
13321
13315
  const recipient = to ?? this.sdk.provider.account;
13322
13316
  if (!recipient) {
13323
13317
  throw new Error("liquidate account: assets recipient not specied");
@@ -13327,7 +13321,7 @@ var CreditAccountsService = class extends SDKConstruct {
13327
13321
  args: [
13328
13322
  account.creditAccount,
13329
13323
  recipient,
13330
- [...priceUpdateCalls, ...preview.calls]
13324
+ [...priceUpdates, ...preview.calls]
13331
13325
  ]
13332
13326
  });
13333
13327
  }
@@ -13398,26 +13392,24 @@ var CreditAccountsService = class extends SDKConstruct {
13398
13392
  * @param accounts
13399
13393
  * @returns
13400
13394
  */
13401
- async #getUpdateForAccounts(accounts, blockNumber) {
13395
+ async #getUpdateForAccount(acc, blockNumber) {
13402
13396
  const tokensByPool = /* @__PURE__ */ new Map();
13403
13397
  const oracleByPool = /* @__PURE__ */ new Map();
13404
- for (const acc of accounts) {
13405
- const market = this.sdk.marketRegister.findByCreditManager(
13406
- acc.creditManager
13407
- );
13408
- const pool = market.state.pool.pool.address;
13409
- oracleByPool.set(pool, market.priceOracle);
13410
- for (const t of acc.tokens) {
13411
- if (t.balance > 10n) {
13412
- const tokens = tokensByPool.get(pool) ?? /* @__PURE__ */ new Set();
13413
- tokens.add(t.token);
13414
- tokensByPool.set(pool, tokens);
13415
- }
13398
+ const market = this.sdk.marketRegister.findByCreditManager(
13399
+ acc.creditManager
13400
+ );
13401
+ const pool = market.state.pool.pool.address;
13402
+ oracleByPool.set(pool, market.priceOracle);
13403
+ for (const t of acc.tokens) {
13404
+ if (t.balance > 10n) {
13405
+ const tokens = tokensByPool.get(pool) ?? /* @__PURE__ */ new Set();
13406
+ tokens.add(t.token);
13407
+ tokensByPool.set(pool, tokens);
13416
13408
  }
13417
13409
  }
13418
13410
  const priceFeeds = [];
13419
- for (const [pool, priceFeedFactory] of oracleByPool.entries()) {
13420
- const tokens = Array.from(tokensByPool.get(pool) ?? []);
13411
+ for (const [pool2, priceFeedFactory] of oracleByPool.entries()) {
13412
+ const tokens = Array.from(tokensByPool.get(pool2) ?? []);
13421
13413
  priceFeeds.push(...priceFeedFactory.priceFeedsForTokens(tokens));
13422
13414
  }
13423
13415
  return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
@@ -13425,22 +13417,46 @@ var CreditAccountsService = class extends SDKConstruct {
13425
13417
  blockNumber
13426
13418
  );
13427
13419
  }
13428
- async #prepareCloseCreditAccount(ca, cm, assetsToKeep, to, slippage = 50n) {
13420
+ /**
13421
+ * Returns account price updates in a non-encoded format
13422
+ * @param acc
13423
+ * @param blockNumber
13424
+ * @returns
13425
+ */
13426
+ async getOnDemandPriceUpdates(acc, blockNumber) {
13429
13427
  const market = this.sdk.marketRegister.findByCreditManager(
13430
- ca.creditManager
13428
+ acc.creditManager
13431
13429
  );
13430
+ const update = await this.#getUpdateForAccount(acc, blockNumber);
13431
+ return market.priceOracle.onDemandPriceUpdates(update);
13432
+ }
13433
+ /**
13434
+ * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...)
13435
+ * @param acc
13436
+ * @param blockNumber
13437
+ * @returns
13438
+ */
13439
+ async getPriceUpdatesForFacade(acc, blockNumber) {
13440
+ const cm = this.sdk.marketRegister.findCreditManager(acc.creditManager);
13441
+ const updates = await this.getOnDemandPriceUpdates(acc, blockNumber);
13442
+ return updates.map(({ token, reserve, data }) => ({
13443
+ target: cm.creditFacade.address,
13444
+ callData: viem.encodeFunctionData({
13445
+ abi: iCreditFacadeV3MulticallAbi,
13446
+ functionName: "onDemandPriceUpdate",
13447
+ args: [token, reserve, data]
13448
+ })
13449
+ }));
13450
+ }
13451
+ async #prepareCloseCreditAccount(ca, cm, assetsToKeep, to, slippage = 50n) {
13432
13452
  const closePath = await this.sdk.router.findBestClosePath(
13433
13453
  ca,
13434
13454
  cm.creditManager,
13435
13455
  slippage
13436
13456
  );
13437
- const priceUpdates = await this.#getUpdateForAccounts([ca]);
13438
- const priceUpdateCalls = market.priceOracle.onDemandPriceUpdates(
13439
- cm.creditFacade.address,
13440
- priceUpdates
13441
- );
13457
+ const priceUpdates = await this.getPriceUpdatesForFacade(ca);
13442
13458
  return [
13443
- ...priceUpdateCalls,
13459
+ ...priceUpdates,
13444
13460
  ...closePath.calls,
13445
13461
  ...this.#prepareDisableQuotas(ca),
13446
13462
  ...this.#prepareDecreaseDebt(ca),
@@ -14997,15 +15013,15 @@ var PriceOracleContract = class extends BaseContract {
14997
15013
  /**
14998
15014
  * Converts previously obtained price updates into CreditFacade multicall entries
14999
15015
  * @param creditFacade
15000
- * @param priceUpdates
15016
+ * @param updates
15001
15017
  * @returns
15002
15018
  */
15003
- onDemandPriceUpdates(creditFacade, priceUpdates) {
15019
+ onDemandPriceUpdates(updates) {
15004
15020
  const result = [];
15005
- if (!priceUpdates) {
15021
+ if (!updates) {
15006
15022
  return result;
15007
15023
  }
15008
- const { txs } = priceUpdates;
15024
+ const { txs } = updates;
15009
15025
  for (const tx of txs) {
15010
15026
  const { to: priceFeed, callData } = tx;
15011
15027
  const [token, reserve] = this.#findTokenForPriceFeed(priceFeed);
@@ -15015,12 +15031,9 @@ var PriceOracleContract = class extends BaseContract {
15015
15031
  });
15016
15032
  const data = args[0];
15017
15033
  result.push({
15018
- target: creditFacade,
15019
- callData: viem.encodeFunctionData({
15020
- abi: iCreditFacadeV3MulticallAbi,
15021
- functionName: "onDemandPriceUpdate",
15022
- args: [token, reserve, data]
15023
- })
15034
+ token,
15035
+ reserve,
15036
+ data
15024
15037
  });
15025
15038
  }
15026
15039
  return result;
@@ -15524,7 +15537,7 @@ var RouterV3Contract = class extends BaseContract {
15524
15537
  * - calls - list of calls which should be done to swap & unwrap everything to underlying token
15525
15538
  */
15526
15539
  async findBestClosePath(ca, cm, slippage) {
15527
- const { pathOptions, expected, leftover, connectors } = this.#getBestClosePathInput(ca, cm);
15540
+ const { pathOptions, expected, leftover, connectors } = this.getFindClosePathInput(ca, cm);
15528
15541
  this.sdk.emit("foundPathOptions", { pathOptions });
15529
15542
  let results = [];
15530
15543
  for (const po of pathOptions) {
@@ -15566,7 +15579,13 @@ var RouterV3Contract = class extends BaseContract {
15566
15579
  });
15567
15580
  return result;
15568
15581
  }
15569
- #getBestClosePathInput(ca, cm) {
15582
+ /**
15583
+ * Finds input to be used with findBestClosePath
15584
+ * @param ca
15585
+ * @param cm
15586
+ * @returns
15587
+ */
15588
+ getFindClosePathInput(ca, cm) {
15570
15589
  const expectedBalances = {};
15571
15590
  const leftoverBalances = {};
15572
15591
  for (const { token: t, balance, mask } of ca.tokens) {
@@ -16830,6 +16830,11 @@ interface PriceFeedsForTokensOptions {
16830
16830
  main?: boolean;
16831
16831
  reserve?: boolean;
16832
16832
  }
16833
+ interface OnDemandPriceUpdate {
16834
+ token: Address;
16835
+ reserve: boolean;
16836
+ data: Hex;
16837
+ }
16833
16838
  declare class PriceOracleContract extends BaseContract<abi$1> {
16834
16839
  #private;
16835
16840
  /**
@@ -16868,10 +16873,10 @@ declare class PriceOracleContract extends BaseContract<abi$1> {
16868
16873
  /**
16869
16874
  * Converts previously obtained price updates into CreditFacade multicall entries
16870
16875
  * @param creditFacade
16871
- * @param priceUpdates
16876
+ * @param updates
16872
16877
  * @returns
16873
16878
  */
16874
- onDemandPriceUpdates(creditFacade: Address, priceUpdates?: UpdatePriceFeedsResult): MultiCall[];
16879
+ onDemandPriceUpdates(updates?: UpdatePriceFeedsResult): OnDemandPriceUpdate[];
16875
16880
  /**
16876
16881
  * Tries to convert amount of token into underlying of current market
16877
16882
  * @param token
@@ -16957,6 +16962,12 @@ interface Asset {
16957
16962
  }
16958
16963
 
16959
16964
  type abi = typeof routerV3Abi;
16965
+ interface FindClosePathInput {
16966
+ pathOptions: PathOptionSerie[];
16967
+ expected: Asset[];
16968
+ leftover: Asset[];
16969
+ connectors: Address[];
16970
+ }
16960
16971
  /**
16961
16972
  * Slice of credit manager data required for router operations
16962
16973
  */
@@ -17014,6 +17025,13 @@ declare class RouterV3Contract extends BaseContract<abi> {
17014
17025
  * - calls - list of calls which should be done to swap & unwrap everything to underlying token
17015
17026
  */
17016
17027
  findBestClosePath(ca: CreditAccountData, cm: CreditManagerSlice, slippage: bigint | number): Promise<RouterCloseResult>;
17028
+ /**
17029
+ * Finds input to be used with findBestClosePath
17030
+ * @param ca
17031
+ * @param cm
17032
+ * @returns
17033
+ */
17034
+ getFindClosePathInput(ca: CreditAccountData, cm: CreditManagerSlice): FindClosePathInput;
17017
17035
  getAvailableConnectors(collateralTokens: Address[]): Address[];
17018
17036
  }
17019
17037
 
@@ -17214,6 +17232,20 @@ declare class CreditAccountsService extends SDKConstruct {
17214
17232
  * @returns
17215
17233
  */
17216
17234
  closeCreditAccount(operation: "close" | "zeroDebt", ca: CreditAccountData, assetsToKeep: Address[], to?: Address, slippage?: bigint): Promise<RawTx>;
17235
+ /**
17236
+ * Returns account price updates in a non-encoded format
17237
+ * @param acc
17238
+ * @param blockNumber
17239
+ * @returns
17240
+ */
17241
+ getOnDemandPriceUpdates(acc: CreditAccountData, blockNumber?: bigint): Promise<OnDemandPriceUpdate[]>;
17242
+ /**
17243
+ * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...)
17244
+ * @param acc
17245
+ * @param blockNumber
17246
+ * @returns
17247
+ */
17248
+ getPriceUpdatesForFacade(acc: CreditAccountData, blockNumber?: bigint): Promise<MultiCall[]>;
17217
17249
  /**
17218
17250
  * Returns addresses of pools of attached markets
17219
17251
  */
@@ -17369,4 +17401,4 @@ type MulticallErrorType = GetChainContractAddressErrorType | ReadContractErrorTy
17369
17401
  */
17370
17402
  declare function simulateMulticall<const contracts extends readonly unknown[], chain extends Chain | undefined, allowFailure extends boolean = true>(client: Client<Transport, chain>, parameters: MulticallParameters<contracts, allowFailure>): Promise<MulticallReturnType<contracts, allowFailure>>;
17371
17403
 
17372
- export { type ACLState, type ACLStateHuman, ADDRESS_0X0, ADDRESS_PROVIDER, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DEGEN_DISTRIBUTOR, AP_DEGEN_NFT, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MULTI_PAUSE, AP_PARTIAL_LIQUIDATION_BOT, AP_PRICE_ORACLE, AP_ROUTER, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractPriceFeedContract, type AccountFactoryStateHuman, AddressLabeller, AddressMap, AddressProviderContractV3_1, type AddressProviderV3State, type AddressProviderV3StateHuman, type AnvilActions, type AnvilClient, type AnvilClientConfig, type Asset, type AssetPriceFeedState, type AssetPriceFeedStateHuman, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, type BaseContractOptions, type BaseContractState, type BaseContractStateHuman, type BasePriceFeedState, type BasePriceFeedStateHuman, BotListContract, type BotListState, type BotListStateHuman, BotPermissions, type BoundedOracleState, type BoundedOracleStateHuman, BoundedPriceFeedContract, ChainlinkPriceFeedContract, CompositePriceFeedContract, type ContractMethod, type ContractsRegisterState, type ContractsRegisterStateHuman, type ControllerTimelockV3State, type ControllerTimelockV3StateHuman, type CoreState, type CoreStateHuman, type CreditAccountData, type CreditAccountFilter, CreditAccountsService, CreditConfiguratorContract, type CreditConfiguratorState, type CreditConfiguratorStateHuman, CreditFacadeContract, type CreditFacadeState, type CreditFacadeStateHuman, CreditFactory, type CreditFactoryState, type CreditFactoryStateHuman, CreditManagerContract, type CreditManagerData, type CreditManagerDebtParams, type CreditManagerDebtParamsHuman, type CreditManagerDebtParamsStruct, type CreditManagerState, type CreditManagerStateHuman, CurveCryptoPriceFeedContract, type CurvePoolStruct, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, type DataCompressorV3State, type DegenDistributorState, type DegenDistributorStateHuman, type DegenNFT2State, type DegenNFT2StateHuman, Erc4626PriceFeedContract, type EtherscanURLParam, GaugeContract, type GaugeParams, type GaugeParamsHuman, type GaugeState, type GaugeStateHuman, GearStakingContract, type GearStakingV3State, type GearStakingV3StateHuman, GearboxSDK, type GearboxState, type GearboxStateHuman, type ILPPriceFeedContract, type ILogger, type IPriceFeedContract, LinearModelContract, type LinearModelState, type LinearModelStateHuman, type LogFn, MAX_UINT256, MIN_INT96, type MarketData, MarketFactory, MarketRegister, type MarketState, type MarketStateHuman, MellowLRTPriceFeedContract, type MultiCall, type MultiPauseState, type MulticallErrorType, type MulticallParameters, type MulticallReturnType, NOT_DEPLOYED, NO_VERSION, type NetworkType, type OpenStrategyResult, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PRICE_DECIMALS, PRICE_DECIMALS_POW, type PathOption, type PathOptionSerie, type PeripheryState, type PeripheryStateHuman, type PolicyStruct, type PolicyStructHuman, PoolContract, type PoolData, PoolFactory, type PoolFactoryState, type PoolFactoryStateHuman, PoolQuotaKeeperContract, type PoolQuotaKeeperData, type PoolQuotaKeeperState, type PoolQuotaKeeperStateHuman, type PoolState, type PoolStateHuman, type PriceFactoryStateHuman, type PriceFeedConstructorArgs, type PriceFeedContractType, type PriceFeedMapEntry, PriceFeedRef, PriceFeedRegister, type PriceFeedState, type PriceFeedStateHuman, type PriceFeedTreeNode, type PriceFeedUsageType, PriceOracleContract, type PriceOracleData, type PriceOracleState, type PriceOracleV3State, type PriceOracleV3StateHuman, Provider, type ProviderOptions, type QuotaParams, type QuotaParamsHuman, RAY, RAY_DECIMALS_POW, type RateKeeperData, type RawTx, type ReadContractOptions, RedstonePriceFeedContract, type RedstonePriceFeedState, type RedstonePriceFeedStateHuman, type RouterCloseResult, type RouterComponentRegisterHuman, type RouterResult, type RouterState, type RouterStateHuman, RouterV3Contract, type RouterV3ContractState, type RouterV3ContractStateHuman, type SDKAttachOptions, SDKConstruct, type SDKEventsMap, SUPPORTED_CHAINS, type SwapOperation, type SwapTask, TIMELOCK, type TVL, type TokenMetaData, type TokenTypeToResolverHuman, USDC, type UpdatePriceFeedsResult, VotingContractStatus, WAD, WAD_DECIMALS_POW, WstETHPriceFeedContract, YearnPriceFeedContract, type ZapperInfo, type ZapperInfoHuman, type ZapperRegisterState, type ZapperRegisterStateHuman, ZeroPriceFeedContract, botPermissionsToString, bytes32ToString, chains, childLogger, convertBaseContractState, convertCoreStateToHuman, convertCreditFactoryStateToHuman, convertGaugeStateToHuman, convertGearboxStateToHuman, convertGearboxStateToHumanLA, convertLinearModelStateToHuman, convertPeripheryStateToHuman, convertPoolFactoryStateToHuman, convertPoolQuotaKeeperStateToHuman, convertPoolStateToHuman, convertPriceFeedStateToHuman, convertPriceOracleStateToHuman, convertRouterStateToHuman, convertRouterV3StateToHuman, convertZapperRegisterStateToHuman, createAnvilClient, createRawTx, detectNetwork, etherscanUrl, filterDust, fmtBinaryMask, formatBN, formatBNvalue, formatBn4dig, formatDuration, formatNumberToString_, halfRAY, isAnvil, json_parse, json_stringify, numberWithCommas, percentFmt, simulateMulticall, toHumanFormat };
17404
+ export { type ACLState, type ACLStateHuman, ADDRESS_0X0, ADDRESS_PROVIDER, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DEGEN_DISTRIBUTOR, AP_DEGEN_NFT, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MULTI_PAUSE, AP_PARTIAL_LIQUIDATION_BOT, AP_PRICE_ORACLE, AP_ROUTER, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractPriceFeedContract, type AccountFactoryStateHuman, AddressLabeller, AddressMap, AddressProviderContractV3_1, type AddressProviderV3State, type AddressProviderV3StateHuman, type AnvilActions, type AnvilClient, type AnvilClientConfig, type Asset, type AssetPriceFeedState, type AssetPriceFeedStateHuman, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, type BaseContractOptions, type BaseContractState, type BaseContractStateHuman, type BasePriceFeedState, type BasePriceFeedStateHuman, BotListContract, type BotListState, type BotListStateHuman, BotPermissions, type BoundedOracleState, type BoundedOracleStateHuman, BoundedPriceFeedContract, ChainlinkPriceFeedContract, CompositePriceFeedContract, type ContractMethod, type ContractsRegisterState, type ContractsRegisterStateHuman, type ControllerTimelockV3State, type ControllerTimelockV3StateHuman, type CoreState, type CoreStateHuman, type CreditAccountData, type CreditAccountFilter, CreditAccountsService, CreditConfiguratorContract, type CreditConfiguratorState, type CreditConfiguratorStateHuman, CreditFacadeContract, type CreditFacadeState, type CreditFacadeStateHuman, CreditFactory, type CreditFactoryState, type CreditFactoryStateHuman, CreditManagerContract, type CreditManagerData, type CreditManagerDebtParams, type CreditManagerDebtParamsHuman, type CreditManagerDebtParamsStruct, type CreditManagerState, type CreditManagerStateHuman, CurveCryptoPriceFeedContract, type CurvePoolStruct, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, type DataCompressorV3State, type DegenDistributorState, type DegenDistributorStateHuman, type DegenNFT2State, type DegenNFT2StateHuman, Erc4626PriceFeedContract, type EtherscanURLParam, type FindClosePathInput, GaugeContract, type GaugeParams, type GaugeParamsHuman, type GaugeState, type GaugeStateHuman, GearStakingContract, type GearStakingV3State, type GearStakingV3StateHuman, GearboxSDK, type GearboxState, type GearboxStateHuman, type ILPPriceFeedContract, type ILogger, type IPriceFeedContract, LinearModelContract, type LinearModelState, type LinearModelStateHuman, type LogFn, MAX_UINT256, MIN_INT96, type MarketData, MarketFactory, MarketRegister, type MarketState, type MarketStateHuman, MellowLRTPriceFeedContract, type MultiCall, type MultiPauseState, type MulticallErrorType, type MulticallParameters, type MulticallReturnType, NOT_DEPLOYED, NO_VERSION, type NetworkType, type OnDemandPriceUpdate, type OpenStrategyResult, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PRICE_DECIMALS, PRICE_DECIMALS_POW, type PathOption, type PathOptionSerie, type PeripheryState, type PeripheryStateHuman, type PolicyStruct, type PolicyStructHuman, PoolContract, type PoolData, PoolFactory, type PoolFactoryState, type PoolFactoryStateHuman, PoolQuotaKeeperContract, type PoolQuotaKeeperData, type PoolQuotaKeeperState, type PoolQuotaKeeperStateHuman, type PoolState, type PoolStateHuman, type PriceFactoryStateHuman, type PriceFeedConstructorArgs, type PriceFeedContractType, type PriceFeedMapEntry, PriceFeedRef, PriceFeedRegister, type PriceFeedState, type PriceFeedStateHuman, type PriceFeedTreeNode, type PriceFeedUsageType, PriceOracleContract, type PriceOracleData, type PriceOracleState, type PriceOracleV3State, type PriceOracleV3StateHuman, Provider, type ProviderOptions, type QuotaParams, type QuotaParamsHuman, RAY, RAY_DECIMALS_POW, type RateKeeperData, type RawTx, type ReadContractOptions, RedstonePriceFeedContract, type RedstonePriceFeedState, type RedstonePriceFeedStateHuman, type RouterCloseResult, type RouterComponentRegisterHuman, type RouterResult, type RouterState, type RouterStateHuman, RouterV3Contract, type RouterV3ContractState, type RouterV3ContractStateHuman, type SDKAttachOptions, SDKConstruct, type SDKEventsMap, SUPPORTED_CHAINS, type SwapOperation, type SwapTask, TIMELOCK, type TVL, type TokenMetaData, type TokenTypeToResolverHuman, USDC, type UpdatePriceFeedsResult, VotingContractStatus, WAD, WAD_DECIMALS_POW, WstETHPriceFeedContract, YearnPriceFeedContract, type ZapperInfo, type ZapperInfoHuman, type ZapperRegisterState, type ZapperRegisterStateHuman, ZeroPriceFeedContract, botPermissionsToString, bytes32ToString, chains, childLogger, convertBaseContractState, convertCoreStateToHuman, convertCreditFactoryStateToHuman, convertGaugeStateToHuman, convertGearboxStateToHuman, convertGearboxStateToHumanLA, convertLinearModelStateToHuman, convertPeripheryStateToHuman, convertPoolFactoryStateToHuman, convertPoolQuotaKeeperStateToHuman, convertPoolStateToHuman, convertPriceFeedStateToHuman, convertPriceOracleStateToHuman, convertRouterStateToHuman, convertRouterV3StateToHuman, convertZapperRegisterStateToHuman, createAnvilClient, createRawTx, detectNetwork, etherscanUrl, filterDust, fmtBinaryMask, formatBN, formatBNvalue, formatBn4dig, formatDuration, formatNumberToString_, halfRAY, isAnvil, json_parse, json_stringify, numberWithCommas, percentFmt, simulateMulticall, toHumanFormat };
@@ -16830,6 +16830,11 @@ interface PriceFeedsForTokensOptions {
16830
16830
  main?: boolean;
16831
16831
  reserve?: boolean;
16832
16832
  }
16833
+ interface OnDemandPriceUpdate {
16834
+ token: Address;
16835
+ reserve: boolean;
16836
+ data: Hex;
16837
+ }
16833
16838
  declare class PriceOracleContract extends BaseContract<abi$1> {
16834
16839
  #private;
16835
16840
  /**
@@ -16868,10 +16873,10 @@ declare class PriceOracleContract extends BaseContract<abi$1> {
16868
16873
  /**
16869
16874
  * Converts previously obtained price updates into CreditFacade multicall entries
16870
16875
  * @param creditFacade
16871
- * @param priceUpdates
16876
+ * @param updates
16872
16877
  * @returns
16873
16878
  */
16874
- onDemandPriceUpdates(creditFacade: Address, priceUpdates?: UpdatePriceFeedsResult): MultiCall[];
16879
+ onDemandPriceUpdates(updates?: UpdatePriceFeedsResult): OnDemandPriceUpdate[];
16875
16880
  /**
16876
16881
  * Tries to convert amount of token into underlying of current market
16877
16882
  * @param token
@@ -16957,6 +16962,12 @@ interface Asset {
16957
16962
  }
16958
16963
 
16959
16964
  type abi = typeof routerV3Abi;
16965
+ interface FindClosePathInput {
16966
+ pathOptions: PathOptionSerie[];
16967
+ expected: Asset[];
16968
+ leftover: Asset[];
16969
+ connectors: Address[];
16970
+ }
16960
16971
  /**
16961
16972
  * Slice of credit manager data required for router operations
16962
16973
  */
@@ -17014,6 +17025,13 @@ declare class RouterV3Contract extends BaseContract<abi> {
17014
17025
  * - calls - list of calls which should be done to swap & unwrap everything to underlying token
17015
17026
  */
17016
17027
  findBestClosePath(ca: CreditAccountData, cm: CreditManagerSlice, slippage: bigint | number): Promise<RouterCloseResult>;
17028
+ /**
17029
+ * Finds input to be used with findBestClosePath
17030
+ * @param ca
17031
+ * @param cm
17032
+ * @returns
17033
+ */
17034
+ getFindClosePathInput(ca: CreditAccountData, cm: CreditManagerSlice): FindClosePathInput;
17017
17035
  getAvailableConnectors(collateralTokens: Address[]): Address[];
17018
17036
  }
17019
17037
 
@@ -17214,6 +17232,20 @@ declare class CreditAccountsService extends SDKConstruct {
17214
17232
  * @returns
17215
17233
  */
17216
17234
  closeCreditAccount(operation: "close" | "zeroDebt", ca: CreditAccountData, assetsToKeep: Address[], to?: Address, slippage?: bigint): Promise<RawTx>;
17235
+ /**
17236
+ * Returns account price updates in a non-encoded format
17237
+ * @param acc
17238
+ * @param blockNumber
17239
+ * @returns
17240
+ */
17241
+ getOnDemandPriceUpdates(acc: CreditAccountData, blockNumber?: bigint): Promise<OnDemandPriceUpdate[]>;
17242
+ /**
17243
+ * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...)
17244
+ * @param acc
17245
+ * @param blockNumber
17246
+ * @returns
17247
+ */
17248
+ getPriceUpdatesForFacade(acc: CreditAccountData, blockNumber?: bigint): Promise<MultiCall[]>;
17217
17249
  /**
17218
17250
  * Returns addresses of pools of attached markets
17219
17251
  */
@@ -17369,4 +17401,4 @@ type MulticallErrorType = GetChainContractAddressErrorType | ReadContractErrorTy
17369
17401
  */
17370
17402
  declare function simulateMulticall<const contracts extends readonly unknown[], chain extends Chain | undefined, allowFailure extends boolean = true>(client: Client<Transport, chain>, parameters: MulticallParameters<contracts, allowFailure>): Promise<MulticallReturnType<contracts, allowFailure>>;
17371
17403
 
17372
- export { type ACLState, type ACLStateHuman, ADDRESS_0X0, ADDRESS_PROVIDER, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DEGEN_DISTRIBUTOR, AP_DEGEN_NFT, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MULTI_PAUSE, AP_PARTIAL_LIQUIDATION_BOT, AP_PRICE_ORACLE, AP_ROUTER, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractPriceFeedContract, type AccountFactoryStateHuman, AddressLabeller, AddressMap, AddressProviderContractV3_1, type AddressProviderV3State, type AddressProviderV3StateHuman, type AnvilActions, type AnvilClient, type AnvilClientConfig, type Asset, type AssetPriceFeedState, type AssetPriceFeedStateHuman, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, type BaseContractOptions, type BaseContractState, type BaseContractStateHuman, type BasePriceFeedState, type BasePriceFeedStateHuman, BotListContract, type BotListState, type BotListStateHuman, BotPermissions, type BoundedOracleState, type BoundedOracleStateHuman, BoundedPriceFeedContract, ChainlinkPriceFeedContract, CompositePriceFeedContract, type ContractMethod, type ContractsRegisterState, type ContractsRegisterStateHuman, type ControllerTimelockV3State, type ControllerTimelockV3StateHuman, type CoreState, type CoreStateHuman, type CreditAccountData, type CreditAccountFilter, CreditAccountsService, CreditConfiguratorContract, type CreditConfiguratorState, type CreditConfiguratorStateHuman, CreditFacadeContract, type CreditFacadeState, type CreditFacadeStateHuman, CreditFactory, type CreditFactoryState, type CreditFactoryStateHuman, CreditManagerContract, type CreditManagerData, type CreditManagerDebtParams, type CreditManagerDebtParamsHuman, type CreditManagerDebtParamsStruct, type CreditManagerState, type CreditManagerStateHuman, CurveCryptoPriceFeedContract, type CurvePoolStruct, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, type DataCompressorV3State, type DegenDistributorState, type DegenDistributorStateHuman, type DegenNFT2State, type DegenNFT2StateHuman, Erc4626PriceFeedContract, type EtherscanURLParam, GaugeContract, type GaugeParams, type GaugeParamsHuman, type GaugeState, type GaugeStateHuman, GearStakingContract, type GearStakingV3State, type GearStakingV3StateHuman, GearboxSDK, type GearboxState, type GearboxStateHuman, type ILPPriceFeedContract, type ILogger, type IPriceFeedContract, LinearModelContract, type LinearModelState, type LinearModelStateHuman, type LogFn, MAX_UINT256, MIN_INT96, type MarketData, MarketFactory, MarketRegister, type MarketState, type MarketStateHuman, MellowLRTPriceFeedContract, type MultiCall, type MultiPauseState, type MulticallErrorType, type MulticallParameters, type MulticallReturnType, NOT_DEPLOYED, NO_VERSION, type NetworkType, type OpenStrategyResult, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PRICE_DECIMALS, PRICE_DECIMALS_POW, type PathOption, type PathOptionSerie, type PeripheryState, type PeripheryStateHuman, type PolicyStruct, type PolicyStructHuman, PoolContract, type PoolData, PoolFactory, type PoolFactoryState, type PoolFactoryStateHuman, PoolQuotaKeeperContract, type PoolQuotaKeeperData, type PoolQuotaKeeperState, type PoolQuotaKeeperStateHuman, type PoolState, type PoolStateHuman, type PriceFactoryStateHuman, type PriceFeedConstructorArgs, type PriceFeedContractType, type PriceFeedMapEntry, PriceFeedRef, PriceFeedRegister, type PriceFeedState, type PriceFeedStateHuman, type PriceFeedTreeNode, type PriceFeedUsageType, PriceOracleContract, type PriceOracleData, type PriceOracleState, type PriceOracleV3State, type PriceOracleV3StateHuman, Provider, type ProviderOptions, type QuotaParams, type QuotaParamsHuman, RAY, RAY_DECIMALS_POW, type RateKeeperData, type RawTx, type ReadContractOptions, RedstonePriceFeedContract, type RedstonePriceFeedState, type RedstonePriceFeedStateHuman, type RouterCloseResult, type RouterComponentRegisterHuman, type RouterResult, type RouterState, type RouterStateHuman, RouterV3Contract, type RouterV3ContractState, type RouterV3ContractStateHuman, type SDKAttachOptions, SDKConstruct, type SDKEventsMap, SUPPORTED_CHAINS, type SwapOperation, type SwapTask, TIMELOCK, type TVL, type TokenMetaData, type TokenTypeToResolverHuman, USDC, type UpdatePriceFeedsResult, VotingContractStatus, WAD, WAD_DECIMALS_POW, WstETHPriceFeedContract, YearnPriceFeedContract, type ZapperInfo, type ZapperInfoHuman, type ZapperRegisterState, type ZapperRegisterStateHuman, ZeroPriceFeedContract, botPermissionsToString, bytes32ToString, chains, childLogger, convertBaseContractState, convertCoreStateToHuman, convertCreditFactoryStateToHuman, convertGaugeStateToHuman, convertGearboxStateToHuman, convertGearboxStateToHumanLA, convertLinearModelStateToHuman, convertPeripheryStateToHuman, convertPoolFactoryStateToHuman, convertPoolQuotaKeeperStateToHuman, convertPoolStateToHuman, convertPriceFeedStateToHuman, convertPriceOracleStateToHuman, convertRouterStateToHuman, convertRouterV3StateToHuman, convertZapperRegisterStateToHuman, createAnvilClient, createRawTx, detectNetwork, etherscanUrl, filterDust, fmtBinaryMask, formatBN, formatBNvalue, formatBn4dig, formatDuration, formatNumberToString_, halfRAY, isAnvil, json_parse, json_stringify, numberWithCommas, percentFmt, simulateMulticall, toHumanFormat };
17404
+ export { type ACLState, type ACLStateHuman, ADDRESS_0X0, ADDRESS_PROVIDER, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DEGEN_DISTRIBUTOR, AP_DEGEN_NFT, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MULTI_PAUSE, AP_PARTIAL_LIQUIDATION_BOT, AP_PRICE_ORACLE, AP_ROUTER, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractPriceFeedContract, type AccountFactoryStateHuman, AddressLabeller, AddressMap, AddressProviderContractV3_1, type AddressProviderV3State, type AddressProviderV3StateHuman, type AnvilActions, type AnvilClient, type AnvilClientConfig, type Asset, type AssetPriceFeedState, type AssetPriceFeedStateHuman, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, type BaseContractOptions, type BaseContractState, type BaseContractStateHuman, type BasePriceFeedState, type BasePriceFeedStateHuman, BotListContract, type BotListState, type BotListStateHuman, BotPermissions, type BoundedOracleState, type BoundedOracleStateHuman, BoundedPriceFeedContract, ChainlinkPriceFeedContract, CompositePriceFeedContract, type ContractMethod, type ContractsRegisterState, type ContractsRegisterStateHuman, type ControllerTimelockV3State, type ControllerTimelockV3StateHuman, type CoreState, type CoreStateHuman, type CreditAccountData, type CreditAccountFilter, CreditAccountsService, CreditConfiguratorContract, type CreditConfiguratorState, type CreditConfiguratorStateHuman, CreditFacadeContract, type CreditFacadeState, type CreditFacadeStateHuman, CreditFactory, type CreditFactoryState, type CreditFactoryStateHuman, CreditManagerContract, type CreditManagerData, type CreditManagerDebtParams, type CreditManagerDebtParamsHuman, type CreditManagerDebtParamsStruct, type CreditManagerState, type CreditManagerStateHuman, CurveCryptoPriceFeedContract, type CurvePoolStruct, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, type DataCompressorV3State, type DegenDistributorState, type DegenDistributorStateHuman, type DegenNFT2State, type DegenNFT2StateHuman, Erc4626PriceFeedContract, type EtherscanURLParam, type FindClosePathInput, GaugeContract, type GaugeParams, type GaugeParamsHuman, type GaugeState, type GaugeStateHuman, GearStakingContract, type GearStakingV3State, type GearStakingV3StateHuman, GearboxSDK, type GearboxState, type GearboxStateHuman, type ILPPriceFeedContract, type ILogger, type IPriceFeedContract, LinearModelContract, type LinearModelState, type LinearModelStateHuman, type LogFn, MAX_UINT256, MIN_INT96, type MarketData, MarketFactory, MarketRegister, type MarketState, type MarketStateHuman, MellowLRTPriceFeedContract, type MultiCall, type MultiPauseState, type MulticallErrorType, type MulticallParameters, type MulticallReturnType, NOT_DEPLOYED, NO_VERSION, type NetworkType, type OnDemandPriceUpdate, type OpenStrategyResult, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PRICE_DECIMALS, PRICE_DECIMALS_POW, type PathOption, type PathOptionSerie, type PeripheryState, type PeripheryStateHuman, type PolicyStruct, type PolicyStructHuman, PoolContract, type PoolData, PoolFactory, type PoolFactoryState, type PoolFactoryStateHuman, PoolQuotaKeeperContract, type PoolQuotaKeeperData, type PoolQuotaKeeperState, type PoolQuotaKeeperStateHuman, type PoolState, type PoolStateHuman, type PriceFactoryStateHuman, type PriceFeedConstructorArgs, type PriceFeedContractType, type PriceFeedMapEntry, PriceFeedRef, PriceFeedRegister, type PriceFeedState, type PriceFeedStateHuman, type PriceFeedTreeNode, type PriceFeedUsageType, PriceOracleContract, type PriceOracleData, type PriceOracleState, type PriceOracleV3State, type PriceOracleV3StateHuman, Provider, type ProviderOptions, type QuotaParams, type QuotaParamsHuman, RAY, RAY_DECIMALS_POW, type RateKeeperData, type RawTx, type ReadContractOptions, RedstonePriceFeedContract, type RedstonePriceFeedState, type RedstonePriceFeedStateHuman, type RouterCloseResult, type RouterComponentRegisterHuman, type RouterResult, type RouterState, type RouterStateHuman, RouterV3Contract, type RouterV3ContractState, type RouterV3ContractStateHuman, type SDKAttachOptions, SDKConstruct, type SDKEventsMap, SUPPORTED_CHAINS, type SwapOperation, type SwapTask, TIMELOCK, type TVL, type TokenMetaData, type TokenTypeToResolverHuman, USDC, type UpdatePriceFeedsResult, VotingContractStatus, WAD, WAD_DECIMALS_POW, WstETHPriceFeedContract, YearnPriceFeedContract, type ZapperInfo, type ZapperInfoHuman, type ZapperRegisterState, type ZapperRegisterStateHuman, ZeroPriceFeedContract, botPermissionsToString, bytes32ToString, chains, childLogger, convertBaseContractState, convertCoreStateToHuman, convertCreditFactoryStateToHuman, convertGaugeStateToHuman, convertGearboxStateToHuman, convertGearboxStateToHumanLA, convertLinearModelStateToHuman, convertPeripheryStateToHuman, convertPoolFactoryStateToHuman, convertPoolQuotaKeeperStateToHuman, convertPoolStateToHuman, convertPriceFeedStateToHuman, convertPriceOracleStateToHuman, convertRouterStateToHuman, convertRouterV3StateToHuman, convertZapperRegisterStateToHuman, createAnvilClient, createRawTx, detectNetwork, etherscanUrl, filterDust, fmtBinaryMask, formatBN, formatBNvalue, formatBn4dig, formatDuration, formatNumberToString_, halfRAY, isAnvil, json_parse, json_stringify, numberWithCommas, percentFmt, simulateMulticall, toHumanFormat };
@@ -13214,6 +13214,7 @@ var CreditAccountsService = class extends SDKConstruct {
13214
13214
  functionName: "getCreditAccountData",
13215
13215
  args: [account],
13216
13216
  blockNumber
13217
+ // TODO: we should cache price updates for block to speed up optimistic liquidator
13217
13218
  });
13218
13219
  } catch (e) {
13219
13220
  return void 0;
@@ -13303,19 +13304,12 @@ var CreditAccountsService = class extends SDKConstruct {
13303
13304
  */
13304
13305
  async fullyLiquidate(account, to, slippage = 50n) {
13305
13306
  const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
13306
- const market = this.sdk.marketRegister.findByCreditManager(
13307
- account.creditManager
13308
- );
13309
13307
  const preview = await this.sdk.router.findBestClosePath(
13310
13308
  account,
13311
13309
  cm.creditManager,
13312
13310
  slippage
13313
13311
  );
13314
- const priceUpdates = await this.#getUpdateForAccounts([account]);
13315
- const priceUpdateCalls = market.priceOracle.onDemandPriceUpdates(
13316
- cm.creditFacade.address,
13317
- priceUpdates
13318
- );
13312
+ const priceUpdates = await this.getPriceUpdatesForFacade(account);
13319
13313
  const recipient = to ?? this.sdk.provider.account;
13320
13314
  if (!recipient) {
13321
13315
  throw new Error("liquidate account: assets recipient not specied");
@@ -13325,7 +13319,7 @@ var CreditAccountsService = class extends SDKConstruct {
13325
13319
  args: [
13326
13320
  account.creditAccount,
13327
13321
  recipient,
13328
- [...priceUpdateCalls, ...preview.calls]
13322
+ [...priceUpdates, ...preview.calls]
13329
13323
  ]
13330
13324
  });
13331
13325
  }
@@ -13396,26 +13390,24 @@ var CreditAccountsService = class extends SDKConstruct {
13396
13390
  * @param accounts
13397
13391
  * @returns
13398
13392
  */
13399
- async #getUpdateForAccounts(accounts, blockNumber) {
13393
+ async #getUpdateForAccount(acc, blockNumber) {
13400
13394
  const tokensByPool = /* @__PURE__ */ new Map();
13401
13395
  const oracleByPool = /* @__PURE__ */ new Map();
13402
- for (const acc of accounts) {
13403
- const market = this.sdk.marketRegister.findByCreditManager(
13404
- acc.creditManager
13405
- );
13406
- const pool = market.state.pool.pool.address;
13407
- oracleByPool.set(pool, market.priceOracle);
13408
- for (const t of acc.tokens) {
13409
- if (t.balance > 10n) {
13410
- const tokens = tokensByPool.get(pool) ?? /* @__PURE__ */ new Set();
13411
- tokens.add(t.token);
13412
- tokensByPool.set(pool, tokens);
13413
- }
13396
+ const market = this.sdk.marketRegister.findByCreditManager(
13397
+ acc.creditManager
13398
+ );
13399
+ const pool = market.state.pool.pool.address;
13400
+ oracleByPool.set(pool, market.priceOracle);
13401
+ for (const t of acc.tokens) {
13402
+ if (t.balance > 10n) {
13403
+ const tokens = tokensByPool.get(pool) ?? /* @__PURE__ */ new Set();
13404
+ tokens.add(t.token);
13405
+ tokensByPool.set(pool, tokens);
13414
13406
  }
13415
13407
  }
13416
13408
  const priceFeeds = [];
13417
- for (const [pool, priceFeedFactory] of oracleByPool.entries()) {
13418
- const tokens = Array.from(tokensByPool.get(pool) ?? []);
13409
+ for (const [pool2, priceFeedFactory] of oracleByPool.entries()) {
13410
+ const tokens = Array.from(tokensByPool.get(pool2) ?? []);
13419
13411
  priceFeeds.push(...priceFeedFactory.priceFeedsForTokens(tokens));
13420
13412
  }
13421
13413
  return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
@@ -13423,22 +13415,46 @@ var CreditAccountsService = class extends SDKConstruct {
13423
13415
  blockNumber
13424
13416
  );
13425
13417
  }
13426
- async #prepareCloseCreditAccount(ca, cm, assetsToKeep, to, slippage = 50n) {
13418
+ /**
13419
+ * Returns account price updates in a non-encoded format
13420
+ * @param acc
13421
+ * @param blockNumber
13422
+ * @returns
13423
+ */
13424
+ async getOnDemandPriceUpdates(acc, blockNumber) {
13427
13425
  const market = this.sdk.marketRegister.findByCreditManager(
13428
- ca.creditManager
13426
+ acc.creditManager
13429
13427
  );
13428
+ const update = await this.#getUpdateForAccount(acc, blockNumber);
13429
+ return market.priceOracle.onDemandPriceUpdates(update);
13430
+ }
13431
+ /**
13432
+ * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...)
13433
+ * @param acc
13434
+ * @param blockNumber
13435
+ * @returns
13436
+ */
13437
+ async getPriceUpdatesForFacade(acc, blockNumber) {
13438
+ const cm = this.sdk.marketRegister.findCreditManager(acc.creditManager);
13439
+ const updates = await this.getOnDemandPriceUpdates(acc, blockNumber);
13440
+ return updates.map(({ token, reserve, data }) => ({
13441
+ target: cm.creditFacade.address,
13442
+ callData: encodeFunctionData({
13443
+ abi: iCreditFacadeV3MulticallAbi,
13444
+ functionName: "onDemandPriceUpdate",
13445
+ args: [token, reserve, data]
13446
+ })
13447
+ }));
13448
+ }
13449
+ async #prepareCloseCreditAccount(ca, cm, assetsToKeep, to, slippage = 50n) {
13430
13450
  const closePath = await this.sdk.router.findBestClosePath(
13431
13451
  ca,
13432
13452
  cm.creditManager,
13433
13453
  slippage
13434
13454
  );
13435
- const priceUpdates = await this.#getUpdateForAccounts([ca]);
13436
- const priceUpdateCalls = market.priceOracle.onDemandPriceUpdates(
13437
- cm.creditFacade.address,
13438
- priceUpdates
13439
- );
13455
+ const priceUpdates = await this.getPriceUpdatesForFacade(ca);
13440
13456
  return [
13441
- ...priceUpdateCalls,
13457
+ ...priceUpdates,
13442
13458
  ...closePath.calls,
13443
13459
  ...this.#prepareDisableQuotas(ca),
13444
13460
  ...this.#prepareDecreaseDebt(ca),
@@ -14995,15 +15011,15 @@ var PriceOracleContract = class extends BaseContract {
14995
15011
  /**
14996
15012
  * Converts previously obtained price updates into CreditFacade multicall entries
14997
15013
  * @param creditFacade
14998
- * @param priceUpdates
15014
+ * @param updates
14999
15015
  * @returns
15000
15016
  */
15001
- onDemandPriceUpdates(creditFacade, priceUpdates) {
15017
+ onDemandPriceUpdates(updates) {
15002
15018
  const result = [];
15003
- if (!priceUpdates) {
15019
+ if (!updates) {
15004
15020
  return result;
15005
15021
  }
15006
- const { txs } = priceUpdates;
15022
+ const { txs } = updates;
15007
15023
  for (const tx of txs) {
15008
15024
  const { to: priceFeed, callData } = tx;
15009
15025
  const [token, reserve] = this.#findTokenForPriceFeed(priceFeed);
@@ -15013,12 +15029,9 @@ var PriceOracleContract = class extends BaseContract {
15013
15029
  });
15014
15030
  const data = args[0];
15015
15031
  result.push({
15016
- target: creditFacade,
15017
- callData: encodeFunctionData({
15018
- abi: iCreditFacadeV3MulticallAbi,
15019
- functionName: "onDemandPriceUpdate",
15020
- args: [token, reserve, data]
15021
- })
15032
+ token,
15033
+ reserve,
15034
+ data
15022
15035
  });
15023
15036
  }
15024
15037
  return result;
@@ -15522,7 +15535,7 @@ var RouterV3Contract = class extends BaseContract {
15522
15535
  * - calls - list of calls which should be done to swap & unwrap everything to underlying token
15523
15536
  */
15524
15537
  async findBestClosePath(ca, cm, slippage) {
15525
- const { pathOptions, expected, leftover, connectors } = this.#getBestClosePathInput(ca, cm);
15538
+ const { pathOptions, expected, leftover, connectors } = this.getFindClosePathInput(ca, cm);
15526
15539
  this.sdk.emit("foundPathOptions", { pathOptions });
15527
15540
  let results = [];
15528
15541
  for (const po of pathOptions) {
@@ -15564,7 +15577,13 @@ var RouterV3Contract = class extends BaseContract {
15564
15577
  });
15565
15578
  return result;
15566
15579
  }
15567
- #getBestClosePathInput(ca, cm) {
15580
+ /**
15581
+ * Finds input to be used with findBestClosePath
15582
+ * @param ca
15583
+ * @param cm
15584
+ * @returns
15585
+ */
15586
+ getFindClosePathInput(ca, cm) {
15568
15587
  const expectedBalances = {};
15569
15588
  const leftoverBalances = {};
15570
15589
  for (const { token: t, balance, mask } of ca.tokens) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.13",
3
+ "version": "3.0.0-vfour.15",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,