@gearbox-protocol/sdk 3.0.0-vfour.87 → 3.0.0-vfour.89

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.
@@ -19671,6 +19671,18 @@ var BaseContract = class extends SDKConstruct {
19671
19671
  }
19672
19672
  return `${this.name}.${decoded.functionName}({${paramsHuman.join(", ")}})`;
19673
19673
  }
19674
+ /**
19675
+ * Return args and function name from calldata
19676
+ * @param calldata
19677
+ * @returns
19678
+ */
19679
+ parseFunctionDataToObject(calldata) {
19680
+ const decoded = viem.decodeFunctionData({
19681
+ abi: this.abi,
19682
+ data: calldata
19683
+ });
19684
+ return decoded;
19685
+ }
19674
19686
  parseFunctionParams(_params) {
19675
19687
  return void 0;
19676
19688
  }
@@ -22418,11 +22430,11 @@ var CreditAccountsService = class extends SDKConstruct {
22418
22430
  */
22419
22431
  async fullyLiquidate(account, to, slippage = 50n) {
22420
22432
  const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
22421
- const routerCloseResult = await this.sdk.router.findBestClosePath(
22422
- account,
22423
- cm.creditManager,
22433
+ const routerCloseResult = await this.sdk.router.findBestClosePath({
22434
+ creditAccount: account,
22435
+ creditManager: cm.creditManager,
22424
22436
  slippage
22425
- );
22437
+ });
22426
22438
  const priceUpdates = await this.getPriceUpdatesForFacade(account);
22427
22439
  const tx = cm.creditFacade.liquidateCreditAccount(
22428
22440
  account.creditAccount,
@@ -22434,7 +22446,7 @@ var CreditAccountsService = class extends SDKConstruct {
22434
22446
  /**
22435
22447
  * Closes credit account or sets debt to zero (but keep account)
22436
22448
  * @param operation
22437
- * @param ca
22449
+ * @param creditAccount
22438
22450
  * @param assetsToWithdraw Tokens to withdraw from credit account
22439
22451
  * @param to Address to withdraw underlying to
22440
22452
  * @param slippage
@@ -22444,13 +22456,17 @@ var CreditAccountsService = class extends SDKConstruct {
22444
22456
  async closeCreditAccount({
22445
22457
  operation,
22446
22458
  assetsToWithdraw,
22447
- ca,
22459
+ creditAccount: ca,
22448
22460
  to,
22449
22461
  slippage = 50n,
22450
22462
  closePath
22451
22463
  }) {
22452
22464
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
22453
- const routerCloseResult = closePath || await this.sdk.router.findBestClosePath(ca, cm.creditManager, slippage);
22465
+ const routerCloseResult = closePath || await this.sdk.router.findBestClosePath({
22466
+ creditAccount: ca,
22467
+ creditManager: cm.creditManager,
22468
+ slippage
22469
+ });
22454
22470
  const calls = [
22455
22471
  ...routerCloseResult.calls,
22456
22472
  ...this.#prepareDisableQuotas(ca),
@@ -22466,7 +22482,7 @@ var CreditAccountsService = class extends SDKConstruct {
22466
22482
  /**
22467
22483
  * Repays credit account or sets debt to zero (but keep account)
22468
22484
  * @param operation
22469
- * @param ca
22485
+ * @param creditAccount
22470
22486
  * @param assetsToWithdraw Tokens to withdraw from credit account
22471
22487
  * @param collateralAssets Tokens to pay for
22472
22488
  * @param to Address to withdraw underlying to
@@ -22478,7 +22494,7 @@ var CreditAccountsService = class extends SDKConstruct {
22478
22494
  operation,
22479
22495
  collateralAssets,
22480
22496
  assetsToWithdraw,
22481
- ca,
22497
+ creditAccount: ca,
22482
22498
  permits,
22483
22499
  to
22484
22500
  }) {
@@ -22489,6 +22505,7 @@ var CreditAccountsService = class extends SDKConstruct {
22489
22505
  ...this.#prepareDisableQuotas(ca),
22490
22506
  ...this.#prepareDecreaseDebt(ca),
22491
22507
  ...this.#prepareDisableTokens(ca),
22508
+ // TODO: probably needs a way to handle reward tokens
22492
22509
  ...assetsToWithdraw.map(
22493
22510
  (t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
22494
22511
  )
@@ -22498,7 +22515,7 @@ var CreditAccountsService = class extends SDKConstruct {
22498
22515
  }
22499
22516
  /**
22500
22517
  * Repays liquidatable credit account
22501
- * @param ca
22518
+ * @param creditAccount
22502
22519
  * @param assetsToWithdraw Tokens to withdraw from credit account
22503
22520
  * @param collateralAssets Tokens to pay for
22504
22521
  * @param to Address to withdraw underlying to
@@ -22508,7 +22525,7 @@ var CreditAccountsService = class extends SDKConstruct {
22508
22525
  async repayAndLiquidateCreditAccount({
22509
22526
  collateralAssets,
22510
22527
  assetsToWithdraw,
22511
- ca,
22528
+ creditAccount: ca,
22512
22529
  permits,
22513
22530
  to
22514
22531
  }) {
@@ -23022,7 +23039,16 @@ var RouterV3Contract = class extends BaseContract {
23022
23039
  * @param slippage
23023
23040
  * @returns
23024
23041
  */
23025
- async findAllSwaps(ca, cm, swapOperation, tokenIn, tokenOut, amount, leftoverAmount, slippage) {
23042
+ async findAllSwaps({
23043
+ creditAccount: ca,
23044
+ creditManager: cm,
23045
+ swapOperation,
23046
+ tokenIn,
23047
+ tokenOut,
23048
+ amount,
23049
+ leftoverAmount,
23050
+ slippage
23051
+ }) {
23026
23052
  const connectors = this.getAvailableConnectors(cm.collateralTokens);
23027
23053
  const swapTask = {
23028
23054
  swapOperation: SWAP_OPERATIONS[swapOperation],
@@ -23052,15 +23078,22 @@ var RouterV3Contract = class extends BaseContract {
23052
23078
  }
23053
23079
  /**
23054
23080
  * Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
23055
- * @param ca
23056
- * @param cm
23081
+ * @param creditAccount
23082
+ * @param creditManager
23057
23083
  * @param tokenIn
23058
23084
  * @param tokenOut
23059
23085
  * @param amount
23060
23086
  * @param slippage
23061
23087
  * @returns
23062
23088
  */
23063
- async findOneTokenPath(ca, cm, tokenIn, tokenOut, amount, slippage) {
23089
+ async findOneTokenPath({
23090
+ creditAccount: ca,
23091
+ creditManager: cm,
23092
+ tokenIn,
23093
+ tokenOut,
23094
+ amount,
23095
+ slippage
23096
+ }) {
23064
23097
  const connectors = this.getAvailableConnectors(cm.collateralTokens);
23065
23098
  const { result } = await this.contract.simulate.findOneTokenPath(
23066
23099
  [
@@ -23083,7 +23116,7 @@ var RouterV3Contract = class extends BaseContract {
23083
23116
  }
23084
23117
  /**
23085
23118
  * @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
23086
- * @param cm CreditManagerData which represents credit manager you want to use to open Credit Account
23119
+ * @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
23087
23120
  * @param expectedBalances Expected balances which would be on account accounting also debt. For example,
23088
23121
  * if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
23089
23122
  * from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
@@ -23092,7 +23125,13 @@ var RouterV3Contract = class extends BaseContract {
23092
23125
  * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
23093
23126
  * @returns PathFinderOpenStrategyResult which
23094
23127
  */
23095
- async findOpenStrategyPath(cm, expectedBalances, leftoverBalances, target, slippage) {
23128
+ async findOpenStrategyPath({
23129
+ creditManager: cm,
23130
+ expectedBalances,
23131
+ leftoverBalances,
23132
+ target,
23133
+ slippage
23134
+ }) {
23096
23135
  const [expectedMap, leftoverMap] = [
23097
23136
  balancesMap(expectedBalances),
23098
23137
  balancesMap(leftoverBalances)
@@ -23134,14 +23173,19 @@ var RouterV3Contract = class extends BaseContract {
23134
23173
  /**
23135
23174
  * @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
23136
23175
  * Can bu used for closing Credit Account and for liquidations as well.
23137
- * @param ca CreditAccountStruct object used for close path computation
23138
- * @param cm CreditManagerSlice for corresponding credit manager
23176
+ * @param creditAccount CreditAccountStruct object used for close path computation
23177
+ * @param creditManager CreditManagerSlice for corresponding credit manager
23139
23178
  * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
23140
23179
  * @return The best option in PathFinderCloseResult format, which
23141
23180
  * - underlyingBalance - total balance of underlying token
23142
23181
  * - calls - list of calls which should be done to swap & unwrap everything to underlying token
23143
23182
  */
23144
- async findBestClosePath(ca, cm, slippage, balances) {
23183
+ async findBestClosePath({
23184
+ creditAccount: ca,
23185
+ creditManager: cm,
23186
+ slippage,
23187
+ balances
23188
+ }) {
23145
23189
  const { pathOptions, expected, leftover, connectors } = this.getFindClosePathInput(
23146
23190
  ca,
23147
23191
  cm,
@@ -23405,6 +23449,31 @@ var GearboxSDK = class _GearboxSDK {
23405
23449
  (call) => this.parseFunctionData(call.target, call.callData)
23406
23450
  );
23407
23451
  }
23452
+ /**
23453
+ * Return args, function, type and address name from contract call
23454
+ * @param address
23455
+ * @param calldata
23456
+ * @returns
23457
+ */
23458
+ parseFunctionDataToObject(address, calldata) {
23459
+ const contract = this.contracts.get(address);
23460
+ return contract ? {
23461
+ ...contract.parseFunctionDataToObject(calldata),
23462
+ address,
23463
+ type: contract.contractType
23464
+ } : null;
23465
+ }
23466
+ /**
23467
+ * Converts multicalls into call info
23468
+ * @param address
23469
+ * @param calldata
23470
+ * @returns
23471
+ */
23472
+ parseMultiCallToObject(calls) {
23473
+ return calls.map(
23474
+ (call) => this.parseFunctionDataToObject(call.target, call.callData)
23475
+ );
23476
+ }
23408
23477
  stateHuman(raw = true) {
23409
23478
  return {
23410
23479
  block: Number(this.currentBlock),
@@ -1,3 +1,4 @@
1
+ import * as viem from 'viem';
1
2
  import { Address, Chain, Transport, PublicClient, Abi, Log, ContractEventName, DecodeFunctionDataReturnType, Hex, ContractFunctionName, EncodeFunctionDataParameters, TransactionReceipt, UnionOmit, RequiredBy, GetContractReturnType, Client, ContractFunctionParameters, CallParameters, MulticallContracts, Narrow, AbiStateMutability, MulticallResults, GetChainContractAddressErrorType, ReadContractErrorType, GetContractErrorReturnType, EncodeFunctionDataErrorType, DecodeFunctionResultErrorType } from 'viem';
2
3
  import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from 'abitype';
3
4
 
@@ -24891,7 +24892,7 @@ interface PathOption {
24891
24892
  }
24892
24893
  type PathOptionSerie = PathOption[];
24893
24894
  interface SwapTask {
24894
- swapOperation: bigint;
24895
+ swapOperation: number;
24895
24896
  creditAccount: Address;
24896
24897
  tokenIn: Address;
24897
24898
  tokenOut: Address;
@@ -24921,6 +24922,37 @@ interface Asset {
24921
24922
  }
24922
24923
 
24923
24924
  type abi = typeof routerV3Abi;
24925
+ interface FindAllSwapsProps {
24926
+ creditAccount: CreditAccountDataSlice;
24927
+ creditManager: CreditManagerSlice;
24928
+ swapOperation: SwapOperation;
24929
+ tokenIn: Address;
24930
+ tokenOut: Address;
24931
+ amount: bigint;
24932
+ leftoverAmount: bigint;
24933
+ slippage: number | bigint;
24934
+ }
24935
+ interface FindOneTokenPathProps {
24936
+ creditAccount: CreditAccountDataSlice;
24937
+ creditManager: CreditManagerSlice;
24938
+ tokenIn: Address;
24939
+ tokenOut: Address;
24940
+ amount: bigint;
24941
+ slippage: number | bigint;
24942
+ }
24943
+ interface FindOpenStrategyPathProps {
24944
+ creditManager: CreditManagerSlice;
24945
+ expectedBalances: Asset[];
24946
+ leftoverBalances: Asset[];
24947
+ target: Address;
24948
+ slippage: number | bigint;
24949
+ }
24950
+ interface FindBestClosePathProps {
24951
+ creditAccount: CreditAccountDataSlice;
24952
+ creditManager: CreditManagerSlice;
24953
+ slippage: bigint | number;
24954
+ balances?: ClosePathBalances;
24955
+ }
24924
24956
  interface FindClosePathInput {
24925
24957
  pathOptions: PathOptionSerie[];
24926
24958
  expected: Asset[];
@@ -24964,21 +24996,21 @@ declare class RouterV3Contract extends BaseContract<abi> implements IHooks<Route
24964
24996
  * @param slippage
24965
24997
  * @returns
24966
24998
  */
24967
- findAllSwaps(ca: CreditAccountDataSlice, cm: CreditManagerSlice, swapOperation: SwapOperation, tokenIn: Address, tokenOut: Address, amount: bigint, leftoverAmount: bigint, slippage: number | bigint): Promise<RouterResult[]>;
24999
+ findAllSwaps({ creditAccount: ca, creditManager: cm, swapOperation, tokenIn, tokenOut, amount, leftoverAmount, slippage, }: FindAllSwapsProps): Promise<RouterResult[]>;
24968
25000
  /**
24969
25001
  * Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
24970
- * @param ca
24971
- * @param cm
25002
+ * @param creditAccount
25003
+ * @param creditManager
24972
25004
  * @param tokenIn
24973
25005
  * @param tokenOut
24974
25006
  * @param amount
24975
25007
  * @param slippage
24976
25008
  * @returns
24977
25009
  */
24978
- findOneTokenPath(ca: CreditAccountDataSlice, cm: CreditManagerSlice, tokenIn: Address, tokenOut: Address, amount: bigint, slippage: number | bigint): Promise<RouterResult>;
25010
+ findOneTokenPath({ creditAccount: ca, creditManager: cm, tokenIn, tokenOut, amount, slippage, }: FindOneTokenPathProps): Promise<RouterResult>;
24979
25011
  /**
24980
25012
  * @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
24981
- * @param cm CreditManagerData which represents credit manager you want to use to open Credit Account
25013
+ * @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
24982
25014
  * @param expectedBalances Expected balances which would be on account accounting also debt. For example,
24983
25015
  * if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
24984
25016
  * from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
@@ -24987,18 +25019,18 @@ declare class RouterV3Contract extends BaseContract<abi> implements IHooks<Route
24987
25019
  * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
24988
25020
  * @returns PathFinderOpenStrategyResult which
24989
25021
  */
24990
- findOpenStrategyPath(cm: CreditManagerSlice, expectedBalances: Asset[], leftoverBalances: Asset[], target: Address, slippage: number | bigint): Promise<OpenStrategyResult>;
25022
+ findOpenStrategyPath({ creditManager: cm, expectedBalances, leftoverBalances, target, slippage, }: FindOpenStrategyPathProps): Promise<OpenStrategyResult>;
24991
25023
  /**
24992
25024
  * @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
24993
25025
  * Can bu used for closing Credit Account and for liquidations as well.
24994
- * @param ca CreditAccountStruct object used for close path computation
24995
- * @param cm CreditManagerSlice for corresponding credit manager
25026
+ * @param creditAccount CreditAccountStruct object used for close path computation
25027
+ * @param creditManager CreditManagerSlice for corresponding credit manager
24996
25028
  * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
24997
25029
  * @return The best option in PathFinderCloseResult format, which
24998
25030
  * - underlyingBalance - total balance of underlying token
24999
25031
  * - calls - list of calls which should be done to swap & unwrap everything to underlying token
25000
25032
  */
25001
- findBestClosePath(ca: CreditAccountDataSlice, cm: CreditManagerSlice, slippage: bigint | number, balances?: ClosePathBalances): Promise<RouterCloseResult>;
25033
+ findBestClosePath({ creditAccount: ca, creditManager: cm, slippage, balances, }: FindBestClosePathProps): Promise<RouterCloseResult>;
25002
25034
  /**
25003
25035
  * Finds input to be used with findBestClosePath
25004
25036
  * @param ca
@@ -25081,6 +25113,30 @@ declare class GearboxSDK {
25081
25113
  * @returns
25082
25114
  */
25083
25115
  parseMultiCall(calls: MultiCall[]): string[];
25116
+ /**
25117
+ * Return args, function, type and address name from contract call
25118
+ * @param address
25119
+ * @param calldata
25120
+ * @returns
25121
+ */
25122
+ parseFunctionDataToObject(address: Address, calldata: Hex): {
25123
+ address: `0x${string}`;
25124
+ type: string;
25125
+ args: any[];
25126
+ functionName: any;
25127
+ } | null;
25128
+ /**
25129
+ * Converts multicalls into call info
25130
+ * @param address
25131
+ * @param calldata
25132
+ * @returns
25133
+ */
25134
+ parseMultiCallToObject(calls: MultiCall[]): ({
25135
+ address: `0x${string}`;
25136
+ type: string;
25137
+ args: any[];
25138
+ functionName: any;
25139
+ } | null)[];
25084
25140
  stateHuman(raw?: boolean): GearboxStateHuman;
25085
25141
  tvl(): Promise<void>;
25086
25142
  /**
@@ -25153,6 +25209,12 @@ declare abstract class BaseContract<abi extends Abi | readonly unknown[]> extend
25153
25209
  * @returns
25154
25210
  */
25155
25211
  parseFunctionData(calldata: Hex): string;
25212
+ /**
25213
+ * Return args and function name from calldata
25214
+ * @param calldata
25215
+ * @returns
25216
+ */
25217
+ parseFunctionDataToObject(calldata: Hex): DecodeFunctionDataReturnType<abi, ContractFunctionName<abi, viem.AbiStateMutability>>;
25156
25218
  parseFunctionParams(_params: DecodeFunctionDataReturnType<abi>): Array<string> | undefined;
25157
25219
  getVersion(): Promise<number>;
25158
25220
  createRawTx<functionName extends ContractFunctionName<abi> | undefined = undefined>(parameters: Omit<EncodeFunctionDataParameters<abi, functionName>, "abi"> & {
@@ -25194,7 +25256,7 @@ interface RepayCreditAccountResult {
25194
25256
  type CloseOptions = "close" | "zeroDebt";
25195
25257
  interface CloseCreditAccountProps {
25196
25258
  operation: CloseOptions;
25197
- ca: CreditAccountDataSlice;
25259
+ creditAccount: CreditAccountDataSlice;
25198
25260
  assetsToWithdraw: Address[];
25199
25261
  to: Address;
25200
25262
  slippage?: bigint;
@@ -25206,7 +25268,7 @@ interface RepayCreditAccountProps extends RepayAndLiquidateCreditAccountProps {
25206
25268
  interface RepayAndLiquidateCreditAccountProps {
25207
25269
  collateralAssets: Asset[];
25208
25270
  assetsToWithdraw: Address[];
25209
- ca: CreditAccountDataSlice;
25271
+ creditAccount: CreditAccountDataSlice;
25210
25272
  to: Address;
25211
25273
  permits: Record<string, PermitResult>;
25212
25274
  }
@@ -25255,18 +25317,18 @@ declare class CreditAccountsService extends SDKConstruct {
25255
25317
  /**
25256
25318
  * Closes credit account or sets debt to zero (but keep account)
25257
25319
  * @param operation
25258
- * @param ca
25320
+ * @param creditAccount
25259
25321
  * @param assetsToWithdraw Tokens to withdraw from credit account
25260
25322
  * @param to Address to withdraw underlying to
25261
25323
  * @param slippage
25262
25324
  * @param closePath
25263
25325
  * @returns
25264
25326
  */
25265
- closeCreditAccount({ operation, assetsToWithdraw, ca, to, slippage, closePath, }: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
25327
+ closeCreditAccount({ operation, assetsToWithdraw, creditAccount: ca, to, slippage, closePath, }: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
25266
25328
  /**
25267
25329
  * Repays credit account or sets debt to zero (but keep account)
25268
25330
  * @param operation
25269
- * @param ca
25331
+ * @param creditAccount
25270
25332
  * @param assetsToWithdraw Tokens to withdraw from credit account
25271
25333
  * @param collateralAssets Tokens to pay for
25272
25334
  * @param to Address to withdraw underlying to
@@ -25274,17 +25336,17 @@ declare class CreditAccountsService extends SDKConstruct {
25274
25336
  * @param permits
25275
25337
  * @returns
25276
25338
  */
25277
- repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, ca, permits, to, }: RepayCreditAccountProps): Promise<RepayCreditAccountResult>;
25339
+ repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayCreditAccountProps): Promise<RepayCreditAccountResult>;
25278
25340
  /**
25279
25341
  * Repays liquidatable credit account
25280
- * @param ca
25342
+ * @param creditAccount
25281
25343
  * @param assetsToWithdraw Tokens to withdraw from credit account
25282
25344
  * @param collateralAssets Tokens to pay for
25283
25345
  * @param to Address to withdraw underlying to
25284
25346
  * @param slippage
25285
25347
  * @returns
25286
25348
  */
25287
- repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw, ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<RepayCreditAccountResult>;
25349
+ repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<RepayCreditAccountResult>;
25288
25350
  /**
25289
25351
  * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
25290
25352
  * @param accounts
@@ -1,3 +1,4 @@
1
+ import * as viem from 'viem';
1
2
  import { Address, Chain, Transport, PublicClient, Abi, Log, ContractEventName, DecodeFunctionDataReturnType, Hex, ContractFunctionName, EncodeFunctionDataParameters, TransactionReceipt, UnionOmit, RequiredBy, GetContractReturnType, Client, ContractFunctionParameters, CallParameters, MulticallContracts, Narrow, AbiStateMutability, MulticallResults, GetChainContractAddressErrorType, ReadContractErrorType, GetContractErrorReturnType, EncodeFunctionDataErrorType, DecodeFunctionResultErrorType } from 'viem';
2
3
  import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from 'abitype';
3
4
 
@@ -24891,7 +24892,7 @@ interface PathOption {
24891
24892
  }
24892
24893
  type PathOptionSerie = PathOption[];
24893
24894
  interface SwapTask {
24894
- swapOperation: bigint;
24895
+ swapOperation: number;
24895
24896
  creditAccount: Address;
24896
24897
  tokenIn: Address;
24897
24898
  tokenOut: Address;
@@ -24921,6 +24922,37 @@ interface Asset {
24921
24922
  }
24922
24923
 
24923
24924
  type abi = typeof routerV3Abi;
24925
+ interface FindAllSwapsProps {
24926
+ creditAccount: CreditAccountDataSlice;
24927
+ creditManager: CreditManagerSlice;
24928
+ swapOperation: SwapOperation;
24929
+ tokenIn: Address;
24930
+ tokenOut: Address;
24931
+ amount: bigint;
24932
+ leftoverAmount: bigint;
24933
+ slippage: number | bigint;
24934
+ }
24935
+ interface FindOneTokenPathProps {
24936
+ creditAccount: CreditAccountDataSlice;
24937
+ creditManager: CreditManagerSlice;
24938
+ tokenIn: Address;
24939
+ tokenOut: Address;
24940
+ amount: bigint;
24941
+ slippage: number | bigint;
24942
+ }
24943
+ interface FindOpenStrategyPathProps {
24944
+ creditManager: CreditManagerSlice;
24945
+ expectedBalances: Asset[];
24946
+ leftoverBalances: Asset[];
24947
+ target: Address;
24948
+ slippage: number | bigint;
24949
+ }
24950
+ interface FindBestClosePathProps {
24951
+ creditAccount: CreditAccountDataSlice;
24952
+ creditManager: CreditManagerSlice;
24953
+ slippage: bigint | number;
24954
+ balances?: ClosePathBalances;
24955
+ }
24924
24956
  interface FindClosePathInput {
24925
24957
  pathOptions: PathOptionSerie[];
24926
24958
  expected: Asset[];
@@ -24964,21 +24996,21 @@ declare class RouterV3Contract extends BaseContract<abi> implements IHooks<Route
24964
24996
  * @param slippage
24965
24997
  * @returns
24966
24998
  */
24967
- findAllSwaps(ca: CreditAccountDataSlice, cm: CreditManagerSlice, swapOperation: SwapOperation, tokenIn: Address, tokenOut: Address, amount: bigint, leftoverAmount: bigint, slippage: number | bigint): Promise<RouterResult[]>;
24999
+ findAllSwaps({ creditAccount: ca, creditManager: cm, swapOperation, tokenIn, tokenOut, amount, leftoverAmount, slippage, }: FindAllSwapsProps): Promise<RouterResult[]>;
24968
25000
  /**
24969
25001
  * Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
24970
- * @param ca
24971
- * @param cm
25002
+ * @param creditAccount
25003
+ * @param creditManager
24972
25004
  * @param tokenIn
24973
25005
  * @param tokenOut
24974
25006
  * @param amount
24975
25007
  * @param slippage
24976
25008
  * @returns
24977
25009
  */
24978
- findOneTokenPath(ca: CreditAccountDataSlice, cm: CreditManagerSlice, tokenIn: Address, tokenOut: Address, amount: bigint, slippage: number | bigint): Promise<RouterResult>;
25010
+ findOneTokenPath({ creditAccount: ca, creditManager: cm, tokenIn, tokenOut, amount, slippage, }: FindOneTokenPathProps): Promise<RouterResult>;
24979
25011
  /**
24980
25012
  * @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
24981
- * @param cm CreditManagerData which represents credit manager you want to use to open Credit Account
25013
+ * @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
24982
25014
  * @param expectedBalances Expected balances which would be on account accounting also debt. For example,
24983
25015
  * if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
24984
25016
  * from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
@@ -24987,18 +25019,18 @@ declare class RouterV3Contract extends BaseContract<abi> implements IHooks<Route
24987
25019
  * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
24988
25020
  * @returns PathFinderOpenStrategyResult which
24989
25021
  */
24990
- findOpenStrategyPath(cm: CreditManagerSlice, expectedBalances: Asset[], leftoverBalances: Asset[], target: Address, slippage: number | bigint): Promise<OpenStrategyResult>;
25022
+ findOpenStrategyPath({ creditManager: cm, expectedBalances, leftoverBalances, target, slippage, }: FindOpenStrategyPathProps): Promise<OpenStrategyResult>;
24991
25023
  /**
24992
25024
  * @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
24993
25025
  * Can bu used for closing Credit Account and for liquidations as well.
24994
- * @param ca CreditAccountStruct object used for close path computation
24995
- * @param cm CreditManagerSlice for corresponding credit manager
25026
+ * @param creditAccount CreditAccountStruct object used for close path computation
25027
+ * @param creditManager CreditManagerSlice for corresponding credit manager
24996
25028
  * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
24997
25029
  * @return The best option in PathFinderCloseResult format, which
24998
25030
  * - underlyingBalance - total balance of underlying token
24999
25031
  * - calls - list of calls which should be done to swap & unwrap everything to underlying token
25000
25032
  */
25001
- findBestClosePath(ca: CreditAccountDataSlice, cm: CreditManagerSlice, slippage: bigint | number, balances?: ClosePathBalances): Promise<RouterCloseResult>;
25033
+ findBestClosePath({ creditAccount: ca, creditManager: cm, slippage, balances, }: FindBestClosePathProps): Promise<RouterCloseResult>;
25002
25034
  /**
25003
25035
  * Finds input to be used with findBestClosePath
25004
25036
  * @param ca
@@ -25081,6 +25113,30 @@ declare class GearboxSDK {
25081
25113
  * @returns
25082
25114
  */
25083
25115
  parseMultiCall(calls: MultiCall[]): string[];
25116
+ /**
25117
+ * Return args, function, type and address name from contract call
25118
+ * @param address
25119
+ * @param calldata
25120
+ * @returns
25121
+ */
25122
+ parseFunctionDataToObject(address: Address, calldata: Hex): {
25123
+ address: `0x${string}`;
25124
+ type: string;
25125
+ args: any[];
25126
+ functionName: any;
25127
+ } | null;
25128
+ /**
25129
+ * Converts multicalls into call info
25130
+ * @param address
25131
+ * @param calldata
25132
+ * @returns
25133
+ */
25134
+ parseMultiCallToObject(calls: MultiCall[]): ({
25135
+ address: `0x${string}`;
25136
+ type: string;
25137
+ args: any[];
25138
+ functionName: any;
25139
+ } | null)[];
25084
25140
  stateHuman(raw?: boolean): GearboxStateHuman;
25085
25141
  tvl(): Promise<void>;
25086
25142
  /**
@@ -25153,6 +25209,12 @@ declare abstract class BaseContract<abi extends Abi | readonly unknown[]> extend
25153
25209
  * @returns
25154
25210
  */
25155
25211
  parseFunctionData(calldata: Hex): string;
25212
+ /**
25213
+ * Return args and function name from calldata
25214
+ * @param calldata
25215
+ * @returns
25216
+ */
25217
+ parseFunctionDataToObject(calldata: Hex): DecodeFunctionDataReturnType<abi, ContractFunctionName<abi, viem.AbiStateMutability>>;
25156
25218
  parseFunctionParams(_params: DecodeFunctionDataReturnType<abi>): Array<string> | undefined;
25157
25219
  getVersion(): Promise<number>;
25158
25220
  createRawTx<functionName extends ContractFunctionName<abi> | undefined = undefined>(parameters: Omit<EncodeFunctionDataParameters<abi, functionName>, "abi"> & {
@@ -25194,7 +25256,7 @@ interface RepayCreditAccountResult {
25194
25256
  type CloseOptions = "close" | "zeroDebt";
25195
25257
  interface CloseCreditAccountProps {
25196
25258
  operation: CloseOptions;
25197
- ca: CreditAccountDataSlice;
25259
+ creditAccount: CreditAccountDataSlice;
25198
25260
  assetsToWithdraw: Address[];
25199
25261
  to: Address;
25200
25262
  slippage?: bigint;
@@ -25206,7 +25268,7 @@ interface RepayCreditAccountProps extends RepayAndLiquidateCreditAccountProps {
25206
25268
  interface RepayAndLiquidateCreditAccountProps {
25207
25269
  collateralAssets: Asset[];
25208
25270
  assetsToWithdraw: Address[];
25209
- ca: CreditAccountDataSlice;
25271
+ creditAccount: CreditAccountDataSlice;
25210
25272
  to: Address;
25211
25273
  permits: Record<string, PermitResult>;
25212
25274
  }
@@ -25255,18 +25317,18 @@ declare class CreditAccountsService extends SDKConstruct {
25255
25317
  /**
25256
25318
  * Closes credit account or sets debt to zero (but keep account)
25257
25319
  * @param operation
25258
- * @param ca
25320
+ * @param creditAccount
25259
25321
  * @param assetsToWithdraw Tokens to withdraw from credit account
25260
25322
  * @param to Address to withdraw underlying to
25261
25323
  * @param slippage
25262
25324
  * @param closePath
25263
25325
  * @returns
25264
25326
  */
25265
- closeCreditAccount({ operation, assetsToWithdraw, ca, to, slippage, closePath, }: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
25327
+ closeCreditAccount({ operation, assetsToWithdraw, creditAccount: ca, to, slippage, closePath, }: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
25266
25328
  /**
25267
25329
  * Repays credit account or sets debt to zero (but keep account)
25268
25330
  * @param operation
25269
- * @param ca
25331
+ * @param creditAccount
25270
25332
  * @param assetsToWithdraw Tokens to withdraw from credit account
25271
25333
  * @param collateralAssets Tokens to pay for
25272
25334
  * @param to Address to withdraw underlying to
@@ -25274,17 +25336,17 @@ declare class CreditAccountsService extends SDKConstruct {
25274
25336
  * @param permits
25275
25337
  * @returns
25276
25338
  */
25277
- repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, ca, permits, to, }: RepayCreditAccountProps): Promise<RepayCreditAccountResult>;
25339
+ repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayCreditAccountProps): Promise<RepayCreditAccountResult>;
25278
25340
  /**
25279
25341
  * Repays liquidatable credit account
25280
- * @param ca
25342
+ * @param creditAccount
25281
25343
  * @param assetsToWithdraw Tokens to withdraw from credit account
25282
25344
  * @param collateralAssets Tokens to pay for
25283
25345
  * @param to Address to withdraw underlying to
25284
25346
  * @param slippage
25285
25347
  * @returns
25286
25348
  */
25287
- repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw, ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<RepayCreditAccountResult>;
25349
+ repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<RepayCreditAccountResult>;
25288
25350
  /**
25289
25351
  * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
25290
25352
  * @param accounts
@@ -19669,6 +19669,18 @@ var BaseContract = class extends SDKConstruct {
19669
19669
  }
19670
19670
  return `${this.name}.${decoded.functionName}({${paramsHuman.join(", ")}})`;
19671
19671
  }
19672
+ /**
19673
+ * Return args and function name from calldata
19674
+ * @param calldata
19675
+ * @returns
19676
+ */
19677
+ parseFunctionDataToObject(calldata) {
19678
+ const decoded = decodeFunctionData({
19679
+ abi: this.abi,
19680
+ data: calldata
19681
+ });
19682
+ return decoded;
19683
+ }
19672
19684
  parseFunctionParams(_params) {
19673
19685
  return void 0;
19674
19686
  }
@@ -22416,11 +22428,11 @@ var CreditAccountsService = class extends SDKConstruct {
22416
22428
  */
22417
22429
  async fullyLiquidate(account, to, slippage = 50n) {
22418
22430
  const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
22419
- const routerCloseResult = await this.sdk.router.findBestClosePath(
22420
- account,
22421
- cm.creditManager,
22431
+ const routerCloseResult = await this.sdk.router.findBestClosePath({
22432
+ creditAccount: account,
22433
+ creditManager: cm.creditManager,
22422
22434
  slippage
22423
- );
22435
+ });
22424
22436
  const priceUpdates = await this.getPriceUpdatesForFacade(account);
22425
22437
  const tx = cm.creditFacade.liquidateCreditAccount(
22426
22438
  account.creditAccount,
@@ -22432,7 +22444,7 @@ var CreditAccountsService = class extends SDKConstruct {
22432
22444
  /**
22433
22445
  * Closes credit account or sets debt to zero (but keep account)
22434
22446
  * @param operation
22435
- * @param ca
22447
+ * @param creditAccount
22436
22448
  * @param assetsToWithdraw Tokens to withdraw from credit account
22437
22449
  * @param to Address to withdraw underlying to
22438
22450
  * @param slippage
@@ -22442,13 +22454,17 @@ var CreditAccountsService = class extends SDKConstruct {
22442
22454
  async closeCreditAccount({
22443
22455
  operation,
22444
22456
  assetsToWithdraw,
22445
- ca,
22457
+ creditAccount: ca,
22446
22458
  to,
22447
22459
  slippage = 50n,
22448
22460
  closePath
22449
22461
  }) {
22450
22462
  const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
22451
- const routerCloseResult = closePath || await this.sdk.router.findBestClosePath(ca, cm.creditManager, slippage);
22463
+ const routerCloseResult = closePath || await this.sdk.router.findBestClosePath({
22464
+ creditAccount: ca,
22465
+ creditManager: cm.creditManager,
22466
+ slippage
22467
+ });
22452
22468
  const calls = [
22453
22469
  ...routerCloseResult.calls,
22454
22470
  ...this.#prepareDisableQuotas(ca),
@@ -22464,7 +22480,7 @@ var CreditAccountsService = class extends SDKConstruct {
22464
22480
  /**
22465
22481
  * Repays credit account or sets debt to zero (but keep account)
22466
22482
  * @param operation
22467
- * @param ca
22483
+ * @param creditAccount
22468
22484
  * @param assetsToWithdraw Tokens to withdraw from credit account
22469
22485
  * @param collateralAssets Tokens to pay for
22470
22486
  * @param to Address to withdraw underlying to
@@ -22476,7 +22492,7 @@ var CreditAccountsService = class extends SDKConstruct {
22476
22492
  operation,
22477
22493
  collateralAssets,
22478
22494
  assetsToWithdraw,
22479
- ca,
22495
+ creditAccount: ca,
22480
22496
  permits,
22481
22497
  to
22482
22498
  }) {
@@ -22487,6 +22503,7 @@ var CreditAccountsService = class extends SDKConstruct {
22487
22503
  ...this.#prepareDisableQuotas(ca),
22488
22504
  ...this.#prepareDecreaseDebt(ca),
22489
22505
  ...this.#prepareDisableTokens(ca),
22506
+ // TODO: probably needs a way to handle reward tokens
22490
22507
  ...assetsToWithdraw.map(
22491
22508
  (t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
22492
22509
  )
@@ -22496,7 +22513,7 @@ var CreditAccountsService = class extends SDKConstruct {
22496
22513
  }
22497
22514
  /**
22498
22515
  * Repays liquidatable credit account
22499
- * @param ca
22516
+ * @param creditAccount
22500
22517
  * @param assetsToWithdraw Tokens to withdraw from credit account
22501
22518
  * @param collateralAssets Tokens to pay for
22502
22519
  * @param to Address to withdraw underlying to
@@ -22506,7 +22523,7 @@ var CreditAccountsService = class extends SDKConstruct {
22506
22523
  async repayAndLiquidateCreditAccount({
22507
22524
  collateralAssets,
22508
22525
  assetsToWithdraw,
22509
- ca,
22526
+ creditAccount: ca,
22510
22527
  permits,
22511
22528
  to
22512
22529
  }) {
@@ -23020,7 +23037,16 @@ var RouterV3Contract = class extends BaseContract {
23020
23037
  * @param slippage
23021
23038
  * @returns
23022
23039
  */
23023
- async findAllSwaps(ca, cm, swapOperation, tokenIn, tokenOut, amount, leftoverAmount, slippage) {
23040
+ async findAllSwaps({
23041
+ creditAccount: ca,
23042
+ creditManager: cm,
23043
+ swapOperation,
23044
+ tokenIn,
23045
+ tokenOut,
23046
+ amount,
23047
+ leftoverAmount,
23048
+ slippage
23049
+ }) {
23024
23050
  const connectors = this.getAvailableConnectors(cm.collateralTokens);
23025
23051
  const swapTask = {
23026
23052
  swapOperation: SWAP_OPERATIONS[swapOperation],
@@ -23050,15 +23076,22 @@ var RouterV3Contract = class extends BaseContract {
23050
23076
  }
23051
23077
  /**
23052
23078
  * Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
23053
- * @param ca
23054
- * @param cm
23079
+ * @param creditAccount
23080
+ * @param creditManager
23055
23081
  * @param tokenIn
23056
23082
  * @param tokenOut
23057
23083
  * @param amount
23058
23084
  * @param slippage
23059
23085
  * @returns
23060
23086
  */
23061
- async findOneTokenPath(ca, cm, tokenIn, tokenOut, amount, slippage) {
23087
+ async findOneTokenPath({
23088
+ creditAccount: ca,
23089
+ creditManager: cm,
23090
+ tokenIn,
23091
+ tokenOut,
23092
+ amount,
23093
+ slippage
23094
+ }) {
23062
23095
  const connectors = this.getAvailableConnectors(cm.collateralTokens);
23063
23096
  const { result } = await this.contract.simulate.findOneTokenPath(
23064
23097
  [
@@ -23081,7 +23114,7 @@ var RouterV3Contract = class extends BaseContract {
23081
23114
  }
23082
23115
  /**
23083
23116
  * @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
23084
- * @param cm CreditManagerData which represents credit manager you want to use to open Credit Account
23117
+ * @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
23085
23118
  * @param expectedBalances Expected balances which would be on account accounting also debt. For example,
23086
23119
  * if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
23087
23120
  * from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
@@ -23090,7 +23123,13 @@ var RouterV3Contract = class extends BaseContract {
23090
23123
  * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
23091
23124
  * @returns PathFinderOpenStrategyResult which
23092
23125
  */
23093
- async findOpenStrategyPath(cm, expectedBalances, leftoverBalances, target, slippage) {
23126
+ async findOpenStrategyPath({
23127
+ creditManager: cm,
23128
+ expectedBalances,
23129
+ leftoverBalances,
23130
+ target,
23131
+ slippage
23132
+ }) {
23094
23133
  const [expectedMap, leftoverMap] = [
23095
23134
  balancesMap(expectedBalances),
23096
23135
  balancesMap(leftoverBalances)
@@ -23132,14 +23171,19 @@ var RouterV3Contract = class extends BaseContract {
23132
23171
  /**
23133
23172
  * @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
23134
23173
  * Can bu used for closing Credit Account and for liquidations as well.
23135
- * @param ca CreditAccountStruct object used for close path computation
23136
- * @param cm CreditManagerSlice for corresponding credit manager
23174
+ * @param creditAccount CreditAccountStruct object used for close path computation
23175
+ * @param creditManager CreditManagerSlice for corresponding credit manager
23137
23176
  * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
23138
23177
  * @return The best option in PathFinderCloseResult format, which
23139
23178
  * - underlyingBalance - total balance of underlying token
23140
23179
  * - calls - list of calls which should be done to swap & unwrap everything to underlying token
23141
23180
  */
23142
- async findBestClosePath(ca, cm, slippage, balances) {
23181
+ async findBestClosePath({
23182
+ creditAccount: ca,
23183
+ creditManager: cm,
23184
+ slippage,
23185
+ balances
23186
+ }) {
23143
23187
  const { pathOptions, expected, leftover, connectors } = this.getFindClosePathInput(
23144
23188
  ca,
23145
23189
  cm,
@@ -23403,6 +23447,31 @@ var GearboxSDK = class _GearboxSDK {
23403
23447
  (call) => this.parseFunctionData(call.target, call.callData)
23404
23448
  );
23405
23449
  }
23450
+ /**
23451
+ * Return args, function, type and address name from contract call
23452
+ * @param address
23453
+ * @param calldata
23454
+ * @returns
23455
+ */
23456
+ parseFunctionDataToObject(address, calldata) {
23457
+ const contract = this.contracts.get(address);
23458
+ return contract ? {
23459
+ ...contract.parseFunctionDataToObject(calldata),
23460
+ address,
23461
+ type: contract.contractType
23462
+ } : null;
23463
+ }
23464
+ /**
23465
+ * Converts multicalls into call info
23466
+ * @param address
23467
+ * @param calldata
23468
+ * @returns
23469
+ */
23470
+ parseMultiCallToObject(calls) {
23471
+ return calls.map(
23472
+ (call) => this.parseFunctionDataToObject(call.target, call.callData)
23473
+ );
23474
+ }
23406
23475
  stateHuman(raw = true) {
23407
23476
  return {
23408
23477
  block: Number(this.currentBlock),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.87",
3
+ "version": "3.0.0-vfour.89",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.cjs",