@gearbox-protocol/sdk 3.0.0-vfour.85 → 3.0.0-vfour.86

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.
@@ -22435,7 +22435,7 @@ var CreditAccountsService = class extends SDKConstruct {
22435
22435
  * Closes credit account or sets debt to zero (but keep account)
22436
22436
  * @param operation
22437
22437
  * @param ca
22438
- * @param assetsToKeep Tokens to withdraw from credit account
22438
+ * @param assetsToWithdraw Tokens to withdraw from credit account
22439
22439
  * @param to Address to withdraw underlying to
22440
22440
  * @param slippage
22441
22441
  * @returns
@@ -22451,6 +22451,24 @@ var CreditAccountsService = class extends SDKConstruct {
22451
22451
  const tx = props.operation === "close" ? cm.creditFacade.closeCreditAccount(props.ca.creditAccount, calls) : cm.creditFacade.multicall(props.ca.creditAccount, calls);
22452
22452
  return { tx, calls, routerCloseResult };
22453
22453
  }
22454
+ /**
22455
+ * Repays credit account or sets debt to zero (but keep account)
22456
+ * @param operation
22457
+ * @param ca
22458
+ * @param assetsToWithdraw Tokens to withdraw from credit account
22459
+ * @param collateralAssets Tokens to pay for
22460
+ * @param to Address to withdraw underlying to
22461
+ * @param slippage
22462
+ * @returns
22463
+ */
22464
+ async repayCreditAccount(props) {
22465
+ const cm = this.sdk.marketRegister.findCreditManager(
22466
+ props.ca.creditManager
22467
+ );
22468
+ const { calls } = await this.#prepareRepayCreditAccount(props);
22469
+ const tx = props.operation === "close" ? cm.creditFacade.closeCreditAccount(props.ca.creditAccount, calls) : cm.creditFacade.multicall(props.ca.creditAccount, calls);
22470
+ return { tx, calls };
22471
+ }
22454
22472
  /**
22455
22473
  * Internal wrapper for CreditAccountCompressor.getCreditAccounts + price updates wrapped into multicall
22456
22474
  * @param args
@@ -22542,7 +22560,7 @@ var CreditAccountsService = class extends SDKConstruct {
22542
22560
  async #prepareCloseCreditAccount({
22543
22561
  ca,
22544
22562
  cm,
22545
- assetsToKeep,
22563
+ assetsToWithdraw,
22546
22564
  to,
22547
22565
  slippage = 50n,
22548
22566
  closePath
@@ -22553,12 +22571,31 @@ var CreditAccountsService = class extends SDKConstruct {
22553
22571
  ...this.#prepareDisableQuotas(ca),
22554
22572
  ...this.#prepareDecreaseDebt(ca),
22555
22573
  ...this.#prepareDisableTokens(ca),
22556
- ...assetsToKeep.map(
22574
+ ...assetsToWithdraw.map(
22557
22575
  (t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
22558
22576
  )
22559
22577
  ];
22560
22578
  return { calls, routerCloseResult };
22561
22579
  }
22580
+ async #prepareRepayCreditAccount({
22581
+ ca,
22582
+ assetsToWithdraw,
22583
+ to,
22584
+ collateralAssets,
22585
+ permits
22586
+ }) {
22587
+ const addCollateral = collateralAssets.filter((a) => a.balance > 0);
22588
+ const calls = [
22589
+ ...this.#prepareAddCollateralCalls(addCollateral, ca, permits),
22590
+ ...this.#prepareDisableQuotas(ca),
22591
+ ...this.#prepareDecreaseDebt(ca),
22592
+ ...this.#prepareDisableTokens(ca),
22593
+ ...assetsToWithdraw.map(
22594
+ (t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
22595
+ )
22596
+ ];
22597
+ return { calls };
22598
+ }
22562
22599
  #prepareDisableQuotas(ca) {
22563
22600
  const calls = [];
22564
22601
  for (const { token, quota } of ca.tokens) {
@@ -22616,6 +22653,30 @@ var CreditAccountsService = class extends SDKConstruct {
22616
22653
  })
22617
22654
  };
22618
22655
  }
22656
+ #prepareAddCollateralCalls(assets, ca, permits) {
22657
+ const calls = assets.map(({ token, balance }) => {
22658
+ const p = permits[token];
22659
+ if (p) {
22660
+ return {
22661
+ target: ca.creditFacade,
22662
+ callData: viem.encodeFunctionData({
22663
+ abi: iCreditFacadeV3MulticallAbi,
22664
+ functionName: "addCollateralWithPermit",
22665
+ args: [token, balance, p.deadline, p.v, p.r, p.s]
22666
+ })
22667
+ };
22668
+ }
22669
+ return {
22670
+ target: ca.creditFacade,
22671
+ callData: viem.encodeFunctionData({
22672
+ abi: iCreditFacadeV3MulticallAbi,
22673
+ functionName: "addCollateral",
22674
+ args: [token, balance]
22675
+ })
22676
+ };
22677
+ });
22678
+ return calls;
22679
+ }
22619
22680
  /**
22620
22681
  * Returns addresses of pools of attached markets
22621
22682
  */
@@ -25187,14 +25187,43 @@ interface CloseCreditAccountResult {
25187
25187
  calls: Array<MultiCall>;
25188
25188
  routerCloseResult: RouterCloseResult;
25189
25189
  }
25190
- interface CloseCreditAccountProps {
25191
- operation: "close" | "zeroDebt";
25190
+ interface RepayCreditAccountResult {
25191
+ tx: RawTx;
25192
+ calls: Array<MultiCall>;
25193
+ }
25194
+ type CloseOptions = "close" | "zeroDebt";
25195
+ interface CloseCreditAccountProps extends Omit<PrepareCloseCreditAccountProps, "cm"> {
25196
+ operation: CloseOptions;
25197
+ }
25198
+ interface PrepareCloseCreditAccountProps {
25199
+ cm: CreditFactory;
25192
25200
  ca: CreditAccountDataSlice;
25193
- assetsToKeep: Address[];
25201
+ assetsToWithdraw: Address[];
25194
25202
  to: Address;
25195
25203
  slippage?: bigint;
25196
25204
  closePath?: RouterCloseResult;
25197
25205
  }
25206
+ interface RepayCreditAccountProps extends PrepareRepayCreditAccountProps {
25207
+ operation: CloseOptions;
25208
+ }
25209
+ interface PrepareRepayCreditAccountProps {
25210
+ collateralAssets: Asset[];
25211
+ assetsToWithdraw: Address[];
25212
+ ca: CreditAccountDataSlice;
25213
+ to: Address;
25214
+ permits: Record<string, PermitResult>;
25215
+ }
25216
+ interface PermitResult {
25217
+ r: Address;
25218
+ s: Address;
25219
+ v: number;
25220
+ token: Address;
25221
+ owner: Address;
25222
+ spender: Address;
25223
+ value: bigint;
25224
+ deadline: bigint;
25225
+ nonce: bigint;
25226
+ }
25198
25227
  declare class CreditAccountsService extends SDKConstruct {
25199
25228
  #private;
25200
25229
  constructor(sdk: GearboxSDK);
@@ -25230,12 +25259,23 @@ declare class CreditAccountsService extends SDKConstruct {
25230
25259
  * Closes credit account or sets debt to zero (but keep account)
25231
25260
  * @param operation
25232
25261
  * @param ca
25233
- * @param assetsToKeep Tokens to withdraw from credit account
25262
+ * @param assetsToWithdraw Tokens to withdraw from credit account
25234
25263
  * @param to Address to withdraw underlying to
25235
25264
  * @param slippage
25236
25265
  * @returns
25237
25266
  */
25238
25267
  closeCreditAccount(props: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
25268
+ /**
25269
+ * Repays credit account or sets debt to zero (but keep account)
25270
+ * @param operation
25271
+ * @param ca
25272
+ * @param assetsToWithdraw Tokens to withdraw from credit account
25273
+ * @param collateralAssets Tokens to pay for
25274
+ * @param to Address to withdraw underlying to
25275
+ * @param slippage
25276
+ * @returns
25277
+ */
25278
+ repayCreditAccount(props: RepayCreditAccountProps): Promise<RepayCreditAccountResult>;
25239
25279
  /**
25240
25280
  * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
25241
25281
  * @param accounts
@@ -25367,4 +25407,4 @@ type MulticallErrorType = GetChainContractAddressErrorType | ReadContractErrorTy
25367
25407
  */
25368
25408
  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>>;
25369
25409
 
25370
- export { ADDRESS_0X0, ADDRESS_PROVIDER, ADDRESS_PROVIDER_BLOCK, AP_ACCOUNT_FACTORY, AP_ACL, AP_ADAPTER_COMPRESSOR, 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_MARKET_CONFIGURATOR, AP_MULTI_PAUSE, AP_PARTIAL_LIQUIDATION_BOT, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_ORACLE, AP_ROUTER, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractPriceFeedContract, type AdapterContractType, type AdapterData, AddressLabeller, AddressMap, AddressProviderContractV3_1, type AddressProviderV3StateHuman, type Asset, type AssetPriceFeedStateHuman, BalancerStablePriceFeedContract, BalancerV2VaultAdapterContract, BalancerWeightedPriceFeedContract, BaseContract, type BaseContractOptions, type BaseContractStateHuman, type BaseParams, type BasePriceFeedStateHuman, BotListContract, type BotListStateHuman, BotPermissions, type BoundedOracleStateHuman, BoundedPriceFeedContract, CamelotV3AdapterContract, ChainlinkPriceFeedContract, type CloseCreditAccountResult, type ClosePathBalances, CompositePriceFeedContract, type ConnectionOptions, type ContractMethod, ConvexV1BaseRewardPoolAdapterContract, ConvexV1BoosterAdapterContract, type CoreStateHuman, type CreditAccountData, type CreditAccountDataSlice, type CreditAccountFilter, CreditAccountsService, CreditConfiguratorContract, type CreditConfiguratorState, type CreditConfiguratorStateHuman, type CreditFacadeState, type CreditFacadeStateHuman, CreditFacadeV300Contract, CreditFacadeV310Contract, CreditFactory, type CreditFactoryStateHuman, CreditManagerContract, type CreditManagerData, type CreditManagerDebtParams, type CreditManagerDebtParamsHuman, type CreditManagerState, type CreditManagerStateHuman, Curve2AssetsAdapterContract, Curve3AssetsAdapterContract, Curve4AssetsAdapterContract, CurveCryptoPriceFeedContract, type CurvePoolStruct, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, CurveV1AdapterStETHContract, CurveV1AdapterStableNGContract, ERC4626AdapterContract, Erc4626PriceFeedContract, type EtherscanURLParam, type FindClosePathInput, type FullyLiquidateAccountResult, GaugeContract, type GaugeParams, type GaugeParamsHuman, type GaugeStateHuman, GearStakingContract, type GearStakingV3StateHuman, GearboxSDK, type GearboxStateHuman, type IAdapterContract, type IBaseContract, type ILPPriceFeedContract, type ILogger, type IPriceFeedContract, LinearModelContract, type LinearModelStateHuman, type LogFn, MAX_UINT16, MAX_UINT256, MIN_INT96, type MarketData, MarketFactory, MarketRegister, type MarketStateHuman, MellowLRTPriceFeedContract, type MultiCall, type MulticallErrorType, type MulticallParameters, type MulticallReturnType, NOT_DEPLOYED, NO_VERSION, type NetworkOptions, type NetworkType, type OnDemandPriceUpdate, type OpenStrategyResult, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PRICE_DECIMALS, PRICE_DECIMALS_POW, type PartialPriceFeedTreeNode, type PathOption, type PathOptionSerie, PoolContract, type PoolData, PoolFactory, type PoolFactoryStateHuman, PoolQuotaKeeperContract, type PoolQuotaKeeperData, type PoolQuotaKeeperStateHuman, type PoolStateHuman, type PriceFeedConstructorArgs, type PriceFeedContractType, type PriceFeedMapEntry, PriceFeedRef, PriceFeedRegister, type PriceFeedRegisterHooks, type PriceFeedStateHuman, type PriceFeedTreeNode, type PriceFeedUsageType, PriceOracleContract, type PriceOracleData, type PriceOracleV3StateHuman, Provider, type QuotaParamsHuman, type QuotaState, RAY, RAY_DECIMALS_POW, type RateKeeperData, type RawTx, RedstonePriceFeedContract, type RedstonePriceFeedStateHuman, type RouterCloseResult, type RouterHooks, type RouterResult, RouterV3Contract, SDKConstruct, type SDKHooks, type SDKOptions, SUPPORTED_CHAINS, type SwapOperation, type SwapTask, type SyncStateOptions, TIMELOCK, type TVL, type TokenMetaData, TokensMeta, type TransportOptions, USDC, UniswapV2AdapterContract, UniswapV3AdapterContract, type UpdatePriceFeedsResult, VelodromeV2RouterAdapterContract, VotingContractStatus, WAD, WAD_DECIMALS_POW, WstETHPriceFeedContract, WstETHV1AdapterContract, YearnPriceFeedContract, YearnV2RouterAdapterContract, type ZapperData, type ZapperStateHuman, ZeroPriceFeedContract, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createRawTx, createTransport, detectNetwork, etherscanUrl, filterDust, fmtBinaryMask, formatBN, formatBNvalue, formatBn4dig, formatDuration, formatNumberToString_, halfRAY, json_parse, json_stringify, numberWithCommas, percentFmt, rawTxToMulticallPriceUpdate, simulateMulticall, toHumanFormat };
25410
+ export { ADDRESS_0X0, ADDRESS_PROVIDER, ADDRESS_PROVIDER_BLOCK, AP_ACCOUNT_FACTORY, AP_ACL, AP_ADAPTER_COMPRESSOR, 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_MARKET_CONFIGURATOR, AP_MULTI_PAUSE, AP_PARTIAL_LIQUIDATION_BOT, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_ORACLE, AP_ROUTER, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractPriceFeedContract, type AdapterContractType, type AdapterData, AddressLabeller, AddressMap, AddressProviderContractV3_1, type AddressProviderV3StateHuman, type Asset, type AssetPriceFeedStateHuman, BalancerStablePriceFeedContract, BalancerV2VaultAdapterContract, BalancerWeightedPriceFeedContract, BaseContract, type BaseContractOptions, type BaseContractStateHuman, type BaseParams, type BasePriceFeedStateHuman, BotListContract, type BotListStateHuman, BotPermissions, type BoundedOracleStateHuman, BoundedPriceFeedContract, CamelotV3AdapterContract, ChainlinkPriceFeedContract, type CloseCreditAccountResult, type ClosePathBalances, CompositePriceFeedContract, type ConnectionOptions, type ContractMethod, ConvexV1BaseRewardPoolAdapterContract, ConvexV1BoosterAdapterContract, type CoreStateHuman, type CreditAccountData, type CreditAccountDataSlice, type CreditAccountFilter, CreditAccountsService, CreditConfiguratorContract, type CreditConfiguratorState, type CreditConfiguratorStateHuman, type CreditFacadeState, type CreditFacadeStateHuman, CreditFacadeV300Contract, CreditFacadeV310Contract, CreditFactory, type CreditFactoryStateHuman, CreditManagerContract, type CreditManagerData, type CreditManagerDebtParams, type CreditManagerDebtParamsHuman, type CreditManagerState, type CreditManagerStateHuman, Curve2AssetsAdapterContract, Curve3AssetsAdapterContract, Curve4AssetsAdapterContract, CurveCryptoPriceFeedContract, type CurvePoolStruct, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, CurveV1AdapterStETHContract, CurveV1AdapterStableNGContract, ERC4626AdapterContract, Erc4626PriceFeedContract, type EtherscanURLParam, type FindClosePathInput, type FullyLiquidateAccountResult, GaugeContract, type GaugeParams, type GaugeParamsHuman, type GaugeStateHuman, GearStakingContract, type GearStakingV3StateHuman, GearboxSDK, type GearboxStateHuman, type IAdapterContract, type IBaseContract, type ILPPriceFeedContract, type ILogger, type IPriceFeedContract, LinearModelContract, type LinearModelStateHuman, type LogFn, MAX_UINT16, MAX_UINT256, MIN_INT96, type MarketData, MarketFactory, MarketRegister, type MarketStateHuman, MellowLRTPriceFeedContract, type MultiCall, type MulticallErrorType, type MulticallParameters, type MulticallReturnType, NOT_DEPLOYED, NO_VERSION, type NetworkOptions, type NetworkType, type OnDemandPriceUpdate, type OpenStrategyResult, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PRICE_DECIMALS, PRICE_DECIMALS_POW, type PartialPriceFeedTreeNode, type PathOption, type PathOptionSerie, type PermitResult, PoolContract, type PoolData, PoolFactory, type PoolFactoryStateHuman, PoolQuotaKeeperContract, type PoolQuotaKeeperData, type PoolQuotaKeeperStateHuman, type PoolStateHuman, type PriceFeedConstructorArgs, type PriceFeedContractType, type PriceFeedMapEntry, PriceFeedRef, PriceFeedRegister, type PriceFeedRegisterHooks, type PriceFeedStateHuman, type PriceFeedTreeNode, type PriceFeedUsageType, PriceOracleContract, type PriceOracleData, type PriceOracleV3StateHuman, Provider, type QuotaParamsHuman, type QuotaState, RAY, RAY_DECIMALS_POW, type RateKeeperData, type RawTx, RedstonePriceFeedContract, type RedstonePriceFeedStateHuman, type RepayCreditAccountResult, type RouterCloseResult, type RouterHooks, type RouterResult, RouterV3Contract, SDKConstruct, type SDKHooks, type SDKOptions, SUPPORTED_CHAINS, type SwapOperation, type SwapTask, type SyncStateOptions, TIMELOCK, type TVL, type TokenMetaData, TokensMeta, type TransportOptions, USDC, UniswapV2AdapterContract, UniswapV3AdapterContract, type UpdatePriceFeedsResult, VelodromeV2RouterAdapterContract, VotingContractStatus, WAD, WAD_DECIMALS_POW, WstETHPriceFeedContract, WstETHV1AdapterContract, YearnPriceFeedContract, YearnV2RouterAdapterContract, type ZapperData, type ZapperStateHuman, ZeroPriceFeedContract, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createRawTx, createTransport, detectNetwork, etherscanUrl, filterDust, fmtBinaryMask, formatBN, formatBNvalue, formatBn4dig, formatDuration, formatNumberToString_, halfRAY, json_parse, json_stringify, numberWithCommas, percentFmt, rawTxToMulticallPriceUpdate, simulateMulticall, toHumanFormat };
@@ -25187,14 +25187,43 @@ interface CloseCreditAccountResult {
25187
25187
  calls: Array<MultiCall>;
25188
25188
  routerCloseResult: RouterCloseResult;
25189
25189
  }
25190
- interface CloseCreditAccountProps {
25191
- operation: "close" | "zeroDebt";
25190
+ interface RepayCreditAccountResult {
25191
+ tx: RawTx;
25192
+ calls: Array<MultiCall>;
25193
+ }
25194
+ type CloseOptions = "close" | "zeroDebt";
25195
+ interface CloseCreditAccountProps extends Omit<PrepareCloseCreditAccountProps, "cm"> {
25196
+ operation: CloseOptions;
25197
+ }
25198
+ interface PrepareCloseCreditAccountProps {
25199
+ cm: CreditFactory;
25192
25200
  ca: CreditAccountDataSlice;
25193
- assetsToKeep: Address[];
25201
+ assetsToWithdraw: Address[];
25194
25202
  to: Address;
25195
25203
  slippage?: bigint;
25196
25204
  closePath?: RouterCloseResult;
25197
25205
  }
25206
+ interface RepayCreditAccountProps extends PrepareRepayCreditAccountProps {
25207
+ operation: CloseOptions;
25208
+ }
25209
+ interface PrepareRepayCreditAccountProps {
25210
+ collateralAssets: Asset[];
25211
+ assetsToWithdraw: Address[];
25212
+ ca: CreditAccountDataSlice;
25213
+ to: Address;
25214
+ permits: Record<string, PermitResult>;
25215
+ }
25216
+ interface PermitResult {
25217
+ r: Address;
25218
+ s: Address;
25219
+ v: number;
25220
+ token: Address;
25221
+ owner: Address;
25222
+ spender: Address;
25223
+ value: bigint;
25224
+ deadline: bigint;
25225
+ nonce: bigint;
25226
+ }
25198
25227
  declare class CreditAccountsService extends SDKConstruct {
25199
25228
  #private;
25200
25229
  constructor(sdk: GearboxSDK);
@@ -25230,12 +25259,23 @@ declare class CreditAccountsService extends SDKConstruct {
25230
25259
  * Closes credit account or sets debt to zero (but keep account)
25231
25260
  * @param operation
25232
25261
  * @param ca
25233
- * @param assetsToKeep Tokens to withdraw from credit account
25262
+ * @param assetsToWithdraw Tokens to withdraw from credit account
25234
25263
  * @param to Address to withdraw underlying to
25235
25264
  * @param slippage
25236
25265
  * @returns
25237
25266
  */
25238
25267
  closeCreditAccount(props: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
25268
+ /**
25269
+ * Repays credit account or sets debt to zero (but keep account)
25270
+ * @param operation
25271
+ * @param ca
25272
+ * @param assetsToWithdraw Tokens to withdraw from credit account
25273
+ * @param collateralAssets Tokens to pay for
25274
+ * @param to Address to withdraw underlying to
25275
+ * @param slippage
25276
+ * @returns
25277
+ */
25278
+ repayCreditAccount(props: RepayCreditAccountProps): Promise<RepayCreditAccountResult>;
25239
25279
  /**
25240
25280
  * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
25241
25281
  * @param accounts
@@ -25367,4 +25407,4 @@ type MulticallErrorType = GetChainContractAddressErrorType | ReadContractErrorTy
25367
25407
  */
25368
25408
  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>>;
25369
25409
 
25370
- export { ADDRESS_0X0, ADDRESS_PROVIDER, ADDRESS_PROVIDER_BLOCK, AP_ACCOUNT_FACTORY, AP_ACL, AP_ADAPTER_COMPRESSOR, 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_MARKET_CONFIGURATOR, AP_MULTI_PAUSE, AP_PARTIAL_LIQUIDATION_BOT, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_ORACLE, AP_ROUTER, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractPriceFeedContract, type AdapterContractType, type AdapterData, AddressLabeller, AddressMap, AddressProviderContractV3_1, type AddressProviderV3StateHuman, type Asset, type AssetPriceFeedStateHuman, BalancerStablePriceFeedContract, BalancerV2VaultAdapterContract, BalancerWeightedPriceFeedContract, BaseContract, type BaseContractOptions, type BaseContractStateHuman, type BaseParams, type BasePriceFeedStateHuman, BotListContract, type BotListStateHuman, BotPermissions, type BoundedOracleStateHuman, BoundedPriceFeedContract, CamelotV3AdapterContract, ChainlinkPriceFeedContract, type CloseCreditAccountResult, type ClosePathBalances, CompositePriceFeedContract, type ConnectionOptions, type ContractMethod, ConvexV1BaseRewardPoolAdapterContract, ConvexV1BoosterAdapterContract, type CoreStateHuman, type CreditAccountData, type CreditAccountDataSlice, type CreditAccountFilter, CreditAccountsService, CreditConfiguratorContract, type CreditConfiguratorState, type CreditConfiguratorStateHuman, type CreditFacadeState, type CreditFacadeStateHuman, CreditFacadeV300Contract, CreditFacadeV310Contract, CreditFactory, type CreditFactoryStateHuman, CreditManagerContract, type CreditManagerData, type CreditManagerDebtParams, type CreditManagerDebtParamsHuman, type CreditManagerState, type CreditManagerStateHuman, Curve2AssetsAdapterContract, Curve3AssetsAdapterContract, Curve4AssetsAdapterContract, CurveCryptoPriceFeedContract, type CurvePoolStruct, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, CurveV1AdapterStETHContract, CurveV1AdapterStableNGContract, ERC4626AdapterContract, Erc4626PriceFeedContract, type EtherscanURLParam, type FindClosePathInput, type FullyLiquidateAccountResult, GaugeContract, type GaugeParams, type GaugeParamsHuman, type GaugeStateHuman, GearStakingContract, type GearStakingV3StateHuman, GearboxSDK, type GearboxStateHuman, type IAdapterContract, type IBaseContract, type ILPPriceFeedContract, type ILogger, type IPriceFeedContract, LinearModelContract, type LinearModelStateHuman, type LogFn, MAX_UINT16, MAX_UINT256, MIN_INT96, type MarketData, MarketFactory, MarketRegister, type MarketStateHuman, MellowLRTPriceFeedContract, type MultiCall, type MulticallErrorType, type MulticallParameters, type MulticallReturnType, NOT_DEPLOYED, NO_VERSION, type NetworkOptions, type NetworkType, type OnDemandPriceUpdate, type OpenStrategyResult, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PRICE_DECIMALS, PRICE_DECIMALS_POW, type PartialPriceFeedTreeNode, type PathOption, type PathOptionSerie, PoolContract, type PoolData, PoolFactory, type PoolFactoryStateHuman, PoolQuotaKeeperContract, type PoolQuotaKeeperData, type PoolQuotaKeeperStateHuman, type PoolStateHuman, type PriceFeedConstructorArgs, type PriceFeedContractType, type PriceFeedMapEntry, PriceFeedRef, PriceFeedRegister, type PriceFeedRegisterHooks, type PriceFeedStateHuman, type PriceFeedTreeNode, type PriceFeedUsageType, PriceOracleContract, type PriceOracleData, type PriceOracleV3StateHuman, Provider, type QuotaParamsHuman, type QuotaState, RAY, RAY_DECIMALS_POW, type RateKeeperData, type RawTx, RedstonePriceFeedContract, type RedstonePriceFeedStateHuman, type RouterCloseResult, type RouterHooks, type RouterResult, RouterV3Contract, SDKConstruct, type SDKHooks, type SDKOptions, SUPPORTED_CHAINS, type SwapOperation, type SwapTask, type SyncStateOptions, TIMELOCK, type TVL, type TokenMetaData, TokensMeta, type TransportOptions, USDC, UniswapV2AdapterContract, UniswapV3AdapterContract, type UpdatePriceFeedsResult, VelodromeV2RouterAdapterContract, VotingContractStatus, WAD, WAD_DECIMALS_POW, WstETHPriceFeedContract, WstETHV1AdapterContract, YearnPriceFeedContract, YearnV2RouterAdapterContract, type ZapperData, type ZapperStateHuman, ZeroPriceFeedContract, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createRawTx, createTransport, detectNetwork, etherscanUrl, filterDust, fmtBinaryMask, formatBN, formatBNvalue, formatBn4dig, formatDuration, formatNumberToString_, halfRAY, json_parse, json_stringify, numberWithCommas, percentFmt, rawTxToMulticallPriceUpdate, simulateMulticall, toHumanFormat };
25410
+ export { ADDRESS_0X0, ADDRESS_PROVIDER, ADDRESS_PROVIDER_BLOCK, AP_ACCOUNT_FACTORY, AP_ACL, AP_ADAPTER_COMPRESSOR, 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_MARKET_CONFIGURATOR, AP_MULTI_PAUSE, AP_PARTIAL_LIQUIDATION_BOT, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_ORACLE, AP_ROUTER, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractPriceFeedContract, type AdapterContractType, type AdapterData, AddressLabeller, AddressMap, AddressProviderContractV3_1, type AddressProviderV3StateHuman, type Asset, type AssetPriceFeedStateHuman, BalancerStablePriceFeedContract, BalancerV2VaultAdapterContract, BalancerWeightedPriceFeedContract, BaseContract, type BaseContractOptions, type BaseContractStateHuman, type BaseParams, type BasePriceFeedStateHuman, BotListContract, type BotListStateHuman, BotPermissions, type BoundedOracleStateHuman, BoundedPriceFeedContract, CamelotV3AdapterContract, ChainlinkPriceFeedContract, type CloseCreditAccountResult, type ClosePathBalances, CompositePriceFeedContract, type ConnectionOptions, type ContractMethod, ConvexV1BaseRewardPoolAdapterContract, ConvexV1BoosterAdapterContract, type CoreStateHuman, type CreditAccountData, type CreditAccountDataSlice, type CreditAccountFilter, CreditAccountsService, CreditConfiguratorContract, type CreditConfiguratorState, type CreditConfiguratorStateHuman, type CreditFacadeState, type CreditFacadeStateHuman, CreditFacadeV300Contract, CreditFacadeV310Contract, CreditFactory, type CreditFactoryStateHuman, CreditManagerContract, type CreditManagerData, type CreditManagerDebtParams, type CreditManagerDebtParamsHuman, type CreditManagerState, type CreditManagerStateHuman, Curve2AssetsAdapterContract, Curve3AssetsAdapterContract, Curve4AssetsAdapterContract, CurveCryptoPriceFeedContract, type CurvePoolStruct, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, CurveV1AdapterStETHContract, CurveV1AdapterStableNGContract, ERC4626AdapterContract, Erc4626PriceFeedContract, type EtherscanURLParam, type FindClosePathInput, type FullyLiquidateAccountResult, GaugeContract, type GaugeParams, type GaugeParamsHuman, type GaugeStateHuman, GearStakingContract, type GearStakingV3StateHuman, GearboxSDK, type GearboxStateHuman, type IAdapterContract, type IBaseContract, type ILPPriceFeedContract, type ILogger, type IPriceFeedContract, LinearModelContract, type LinearModelStateHuman, type LogFn, MAX_UINT16, MAX_UINT256, MIN_INT96, type MarketData, MarketFactory, MarketRegister, type MarketStateHuman, MellowLRTPriceFeedContract, type MultiCall, type MulticallErrorType, type MulticallParameters, type MulticallReturnType, NOT_DEPLOYED, NO_VERSION, type NetworkOptions, type NetworkType, type OnDemandPriceUpdate, type OpenStrategyResult, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PRICE_DECIMALS, PRICE_DECIMALS_POW, type PartialPriceFeedTreeNode, type PathOption, type PathOptionSerie, type PermitResult, PoolContract, type PoolData, PoolFactory, type PoolFactoryStateHuman, PoolQuotaKeeperContract, type PoolQuotaKeeperData, type PoolQuotaKeeperStateHuman, type PoolStateHuman, type PriceFeedConstructorArgs, type PriceFeedContractType, type PriceFeedMapEntry, PriceFeedRef, PriceFeedRegister, type PriceFeedRegisterHooks, type PriceFeedStateHuman, type PriceFeedTreeNode, type PriceFeedUsageType, PriceOracleContract, type PriceOracleData, type PriceOracleV3StateHuman, Provider, type QuotaParamsHuman, type QuotaState, RAY, RAY_DECIMALS_POW, type RateKeeperData, type RawTx, RedstonePriceFeedContract, type RedstonePriceFeedStateHuman, type RepayCreditAccountResult, type RouterCloseResult, type RouterHooks, type RouterResult, RouterV3Contract, SDKConstruct, type SDKHooks, type SDKOptions, SUPPORTED_CHAINS, type SwapOperation, type SwapTask, type SyncStateOptions, TIMELOCK, type TVL, type TokenMetaData, TokensMeta, type TransportOptions, USDC, UniswapV2AdapterContract, UniswapV3AdapterContract, type UpdatePriceFeedsResult, VelodromeV2RouterAdapterContract, VotingContractStatus, WAD, WAD_DECIMALS_POW, WstETHPriceFeedContract, WstETHV1AdapterContract, YearnPriceFeedContract, YearnV2RouterAdapterContract, type ZapperData, type ZapperStateHuman, ZeroPriceFeedContract, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createRawTx, createTransport, detectNetwork, etherscanUrl, filterDust, fmtBinaryMask, formatBN, formatBNvalue, formatBn4dig, formatDuration, formatNumberToString_, halfRAY, json_parse, json_stringify, numberWithCommas, percentFmt, rawTxToMulticallPriceUpdate, simulateMulticall, toHumanFormat };
@@ -22433,7 +22433,7 @@ var CreditAccountsService = class extends SDKConstruct {
22433
22433
  * Closes credit account or sets debt to zero (but keep account)
22434
22434
  * @param operation
22435
22435
  * @param ca
22436
- * @param assetsToKeep Tokens to withdraw from credit account
22436
+ * @param assetsToWithdraw Tokens to withdraw from credit account
22437
22437
  * @param to Address to withdraw underlying to
22438
22438
  * @param slippage
22439
22439
  * @returns
@@ -22449,6 +22449,24 @@ var CreditAccountsService = class extends SDKConstruct {
22449
22449
  const tx = props.operation === "close" ? cm.creditFacade.closeCreditAccount(props.ca.creditAccount, calls) : cm.creditFacade.multicall(props.ca.creditAccount, calls);
22450
22450
  return { tx, calls, routerCloseResult };
22451
22451
  }
22452
+ /**
22453
+ * Repays credit account or sets debt to zero (but keep account)
22454
+ * @param operation
22455
+ * @param ca
22456
+ * @param assetsToWithdraw Tokens to withdraw from credit account
22457
+ * @param collateralAssets Tokens to pay for
22458
+ * @param to Address to withdraw underlying to
22459
+ * @param slippage
22460
+ * @returns
22461
+ */
22462
+ async repayCreditAccount(props) {
22463
+ const cm = this.sdk.marketRegister.findCreditManager(
22464
+ props.ca.creditManager
22465
+ );
22466
+ const { calls } = await this.#prepareRepayCreditAccount(props);
22467
+ const tx = props.operation === "close" ? cm.creditFacade.closeCreditAccount(props.ca.creditAccount, calls) : cm.creditFacade.multicall(props.ca.creditAccount, calls);
22468
+ return { tx, calls };
22469
+ }
22452
22470
  /**
22453
22471
  * Internal wrapper for CreditAccountCompressor.getCreditAccounts + price updates wrapped into multicall
22454
22472
  * @param args
@@ -22540,7 +22558,7 @@ var CreditAccountsService = class extends SDKConstruct {
22540
22558
  async #prepareCloseCreditAccount({
22541
22559
  ca,
22542
22560
  cm,
22543
- assetsToKeep,
22561
+ assetsToWithdraw,
22544
22562
  to,
22545
22563
  slippage = 50n,
22546
22564
  closePath
@@ -22551,12 +22569,31 @@ var CreditAccountsService = class extends SDKConstruct {
22551
22569
  ...this.#prepareDisableQuotas(ca),
22552
22570
  ...this.#prepareDecreaseDebt(ca),
22553
22571
  ...this.#prepareDisableTokens(ca),
22554
- ...assetsToKeep.map(
22572
+ ...assetsToWithdraw.map(
22555
22573
  (t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
22556
22574
  )
22557
22575
  ];
22558
22576
  return { calls, routerCloseResult };
22559
22577
  }
22578
+ async #prepareRepayCreditAccount({
22579
+ ca,
22580
+ assetsToWithdraw,
22581
+ to,
22582
+ collateralAssets,
22583
+ permits
22584
+ }) {
22585
+ const addCollateral = collateralAssets.filter((a) => a.balance > 0);
22586
+ const calls = [
22587
+ ...this.#prepareAddCollateralCalls(addCollateral, ca, permits),
22588
+ ...this.#prepareDisableQuotas(ca),
22589
+ ...this.#prepareDecreaseDebt(ca),
22590
+ ...this.#prepareDisableTokens(ca),
22591
+ ...assetsToWithdraw.map(
22592
+ (t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
22593
+ )
22594
+ ];
22595
+ return { calls };
22596
+ }
22560
22597
  #prepareDisableQuotas(ca) {
22561
22598
  const calls = [];
22562
22599
  for (const { token, quota } of ca.tokens) {
@@ -22614,6 +22651,30 @@ var CreditAccountsService = class extends SDKConstruct {
22614
22651
  })
22615
22652
  };
22616
22653
  }
22654
+ #prepareAddCollateralCalls(assets, ca, permits) {
22655
+ const calls = assets.map(({ token, balance }) => {
22656
+ const p = permits[token];
22657
+ if (p) {
22658
+ return {
22659
+ target: ca.creditFacade,
22660
+ callData: encodeFunctionData({
22661
+ abi: iCreditFacadeV3MulticallAbi,
22662
+ functionName: "addCollateralWithPermit",
22663
+ args: [token, balance, p.deadline, p.v, p.r, p.s]
22664
+ })
22665
+ };
22666
+ }
22667
+ return {
22668
+ target: ca.creditFacade,
22669
+ callData: encodeFunctionData({
22670
+ abi: iCreditFacadeV3MulticallAbi,
22671
+ functionName: "addCollateral",
22672
+ args: [token, balance]
22673
+ })
22674
+ };
22675
+ });
22676
+ return calls;
22677
+ }
22617
22678
  /**
22618
22679
  * Returns addresses of pools of attached markets
22619
22680
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.85",
3
+ "version": "3.0.0-vfour.86",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.cjs",